Jun-03-2021, 09:33 AM
good day. I need to make a simple Batch Processor (run multiple regex for search and replace on files)
Suppose I have 6 or 10 regex formula for search and replace. For example. First 2 regex:
Search:
Replace by:
Search:
Replace by:
and so one,. The Python code should be run these regex, in the order I choose, and to be able to add always a new regex. But for regex, you have to consider also the option .matches newsline
But if I want to make 3 regex replacement, one by one in the order I want, in some .txt files, how can I do that ?
This is a point of view
Suppose I have 6 or 10 regex formula for search and replace. For example. First 2 regex:
Search:
<title>.*\|\K(.*)(</title>)
Replace by:
\x20 Test \x20\2
Search:
<em>.*\|.*</em>)(</title>)
Replace by:
\x20\2
and so one,. The Python code should be run these regex, in the order I choose, and to be able to add always a new regex. But for regex, you have to consider also the option .matches newsline
But if I want to make 3 regex replacement, one by one in the order I want, in some .txt files, how can I do that ?
This is a point of view
import re s = '(zyx)bc' print (re.findall(r'(?<=\()\w+(?=\))|\w', s)) ['zyx', 'b', 'c']