0

I'm trying to translate a subtitle in Google Translate and everything goes ok with just one problem, it removes the comma , from the times. Well, nice. I pasted it on Notepad++ and tried to replace with regex. The time format is:

00:00:44927 -->

and should be

00:00:44,927 -->

So I tried this regex on the Find what field: :(\d){2}(\d){3}( -->)

And this on the replace with field: :$1,$2 -->

The search works but the replace results in this: 00:00:47. It seems that $1 stands for the first number of the first match (\d){2} that is 4 and the second match (\d){3} that is 7.

Why ?

2 Answers 2

1

You need to place the range quantifier {n} inside of your capturing groups. By placing them outside of your capturing groups, you're telling the regex engine that the group is to be repeated nth times instead of the token \d.

Find: :(\d{2})(\d{3})( -->)
Replace: :$1,$2$3

If you wanted to, you could also use lookaround assertions to achieve this.

Find: :\d\d\K(?=\d\d\d)
Replace: ,
Sign up to request clarification or add additional context in comments.

Comments

1

You can just do

(?<=\d\d)(\d{3})(?= -->)

and replace with ,$1

DEMO

You were not capturing \d{3} but just \d which is why your regex didn't work as expected.

1 Comment

Thank you too. Your solution is nice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.