Am new to all this.
I want to batch together several regexes in a single Python script.
Each regex work fine when regex searching through a text file in Notepad++.
However, when combined it's not working. Not working means valid hit found with Notepad++ search is not returned by my Python script.
Running Python 3.7.
Thanks in advance.
# import Python's regular expression module
import re
# file to check; assumes target file is in the same dir as Python script
target = 'test target file.txt'
# declare series of regexes; see top for explanation of each
regexes = [re.compile('^\+'),
re.compile('^[\s+][A-Z]'),
re.compile('\d$\r\n[cm,%,\),l,ml,hPa,°,bar,psi,V,W,]'),
re.compile('^[1-9]{1,2}\.(.*)\r\n^\r\n^[1-9]{1,2}\.(.*)'),
re.compile('FN-'),
re.compile('gfx'),
re.compile('tbl'),
re.compile('Missing link'),
]
# open target file, search for matches, output to screen
with open(target) as fp:
for line in target:
for cnt, line in enumerate(fp):
if any(regex.match(line) for regex in regexes):
print("Line {}: {}".format(cnt, line))