Automating find and replace REGEX expressions in a script

I've made several REGEX expressions which I would like to use to find and replace text in a .srt file:

For example, below, the first is the pattern to be found. The second is the replacement. These work with my text editor just fine:

\n\n(?=\d{1,}\n)
~~~

(?<=-->\s\d{2}\:\d{2}\:\d{2}\,\d{3})\n
```

 (?<=\d)\n(?=\d{2}\:\d{2}\:\d{2}\,\d{3} -->)
'''

There are several more that I have, so I'd like to be able to throw them into a script which would read and replace each successively and for every instance in a given file.

Any idea of a program that could do this? I've had a look at SED, but it seems that using it might require a lot of extra work in editing the expressions.

You may try perl. When it comes to regex and string parsing, perl handles them beautifully. Of course, doesn't mean you don't have other options.

1 Like

Thank you. I've done just that. Perl seems to be the perfect tool for this issue.

Sorry for the late reply.

1 Like