I need help with replacing different strings
-
I am working on a SRT (subtitles) file with time codes like this
00:26.369,0:00:33.450However the comma in the middle needs to be replaced with space–>space
When I do regex Find and replace I can find the piece before the comma with \d\d:\d\d.\d\d\d,
But what do I set as replace string?
\d\d:\d\d.\d\d\d -->
gives dd:dd.ddd --> 0:00:33.450
-
-
@Theo-Richel said in I need help with replacing different strings:
\d\d:\d\d.\d\d\d,
But what do I set as replace string?
\d\d:\d\d.\d\d\d -->
givesdd:dd.ddd --> 0:00:33.450
Thanks for showing what you tried. We really appreciate it when people show their effort when asking questions here. See my footnote for more hints on asking questions successfully.
For replacement strings,
\d
doesn’t mean “match any digit”, it means “give me a literal d”. If you want to re-use text from your match in your substitution, it either needs to not be part of the “match” (which is what @astrosofista’s\K
does: it requires the stuff before the\K
to be present, but it’s not considered part of the “match”), or you need to store the data in a group. For your desire to change00:26.369,0:00:33.450
to
00:26.369 --> 0:00:33.450
I might use
- FIND =
(\d\d:\d\d.\d\d\d),
- REPLACE =
$1\x20-->\x20
$1
means the contents of the first group (the first set of parentheses in the match)- Note: the
\x20
is another way of writing the space character; it makes it easier to copy-paste the expression from the forum into your Replace dialog. If you’re manually typing the regex, you could just have spaces instead of the\x20
edit: forgot the footnote; added.
----Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as plain text using the
</>
toolbar button or manual Markdown syntax. Screenshots can be pasted from the clipbpard to your post usingCtrl+V
to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get… Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries. - FIND =
-
This is not a valid srt timecode.
Whatever you do, it won’t work.
00:26.369,0:00:33.450The correct code is as follows:
00:00:36,833 --> 00:00:39,291