Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append regular expression in SublimeText

I'm very new to regular expressions. I'm working on sublime text and I'm trying to replace all instances of some numbers formatted like this:

00:00:59
00:01:00
00:01:22

and so on.

Appending :00 at the end si it will become 00:00:59:00

I used [0-9]{2}:[0-9]{2}:[0-9]{2} and it finds all instances but I don't know how to append :00 and replace all instances.

like image 900
ppfer Avatar asked Nov 26 '25 03:11

ppfer


1 Answers

You may use

\b[0-9]{2}:[0-9]{2}:[0-9]{2}\b

as the regex and replace with $0:00. Here, $0 is the backreference to the whole match.

enter image description here

                             V   

enter image description here

The \b stand for word boundaries. If you need to avoid matching those timestamps that already have :00 after it, you may consider using

(?<!\d:)\b\d{2}:\d{2}:\d{2}\b(?!:\d)

The (?<!\d:) negative lookbehind will fail the match if the 2 digit substring at the start is preceded with a digit + :, and the (?!:\d) negative lookahead will fail the match if the last 2 digits are followed with : + digit.

like image 148
Wiktor Stribiżew Avatar answered Nov 28 '25 17:11

Wiktor Stribiżew