Page 1 of 1

Coneverting 20190902-123456-xyz to 12:34

Posted: Mon Sep 02, 2019 1:06 pm
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

Posted: Mon Sep 09, 2019 8:17 am
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