Find and replace / Timecode / SRT
-
Hi,
I’m a newbe on notepad++Ideally, I want to tranform this :
00:00:01.181
(text 1)00:00:06.984
<v ->Text 2.</v>00:00:10.105
<v ->Text, Text text.</v>In that :
00:00:01,181 --> 00:00:06,984
(text 1)00:00:06,984 --> 00:00:10,105
<v ->Text 2.</v>00:00:10,105 --> 00:00:13,175
<v ->Text, Text text.</v>1/ I want to replace a point in the figures by a comma:
00:23:55.254 by 00:23:55,254
I found out that i can identify the good point with this [0-9][.][0-9] but can’t replace just the point by the comma…2/ Then I want to add “–>” at the end of each time code.
3/ Then I want to add the following timecode to the previous one
Any ideas ? I have around 5000 lines…
Thanks in advance ;)
Vincent
-
Interesting problem. Here’s a possible regular-expression-based solution, although I’m sure @guy038 could do it more succinctly than this…
Move your caret to the very top of the file before executing the following REPLACE ALL operation.
- Find-what box:
^(\d{2}:\d{2}:\d{2})\.(\d{3})(\R.+?)^(\d{2}:\d{2}:\d{2})[.,](\d{3})
- Replace-with box:
\1,\2 --> \4,\5\3\4.\5
Search mode: ☑ Regular expression -AND- ☑ . matches newline
- Everything else off (for safety, not strictly necessary!):
☐ Match whole word only / ☐ Match case / ☐ Wrap around
IMPORTANT NOTE: It will be necessary to execute the REPLACE-ALL TWO times in order to effect all of the desired changes.
It is a pretty complicated explanation of what the regular expressions are doing, but if you can’t follow it and desire to know, say so.
- Find-what box:
-
Note also that the above won’t do the very LAST timestamp line in the file, which if you think about it, it makes sense because there is no data available to put after the
-->
if such a line were to be created. Thus the last timestamp line is left alone: no conversion of the.
to a,
. Easy enough to fixup the last single line by hand. :-D -
Scott, thanks a lot, it’s working perfectly. It’s looking like magic to me ;)
-
Borrowing somewhat from @guy038 's technique of the lookahead assertion proposed as a solution for this posting: https://notepad-plus-plus.org/community/topic/13761/multiple-copy-paste-notepad , here’s a way of solving the problem presented in the current thread using only ONE Replace-All (instead of TWO as proposed earlier).
Find-what box:
^(\d{2}:\d{2}:\d{2})\.(\d{3})(?=.*?(\d{2}:\d{2}:\d{2})\.(\d{3}))
Replace-with box:\1,\2 -> \3,\4
Search mode:☑ Regular expression -AND- ☑ . matches newline
If this (or ANY) posting was useful, don’t post a “thanks”, just upvote ( click the
^
in the^ 0 v
area on the right ).