Coneverting 20190902-123456-xyz to 12:34

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
terrypin
Posts: 174
Joined: Wed Jul 11, 2007 7:50 am

Coneverting 20190902-123456-xyz to 12:34

Post by terrypin »

I have text in the form yyymmdd-hhmmssABCetc.jpg, such as

20181331-123456.jpg
20190902-012345xyz.bmp
etc

I want to extract only the four characters in positions 10-13 and insert a colon, giving

12:34
01:23

Is that possible with Regex please?

--------------------

EDIT: A few minutes on and Ive made progress. I can extract the four chars with this:

Find ([0-9]{8})-([0-9]{4})(.*)
Replace with \2

Now pondering the colon...

EDIT: Got it!
Find ([0-9]{8})-([0-9]{2})([0-9]{2})(.*)
Replace with \2:\3
User avatar
AmigoJack
Posts: 596
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

If you don't need subpattern results you don't need to define them to begin with:

Find [0-9]{8}-([0-9]{2})([0-9]{2}).*
Replace with \1:\2
Post Reply