>>> line = '\xc2d sdsdfdslkfsdkfjdsf'
>>> pattern_strings = ['\xc2d', '\xe9']
>>> pattern = '|'.join(pattern_strings)
>>> pattern
'\xc2d|\xe9'
>>> import re
>>> re.findall(pattern, line)
['\xc2d']
When I put line
in a file and try to do the same regex, it doen't show up anything
def find_pattern(path):
with open(path) as f:
for line in f:
line = line.strip()
pattern_strings = ['\xc2d', '\xe9'] # or using ['\\xc2d', '\xe9'] doesn't help
pattern = '|'.join(pattern_strings)
print re.findall(pattern, line)
where path
is a file looked as following
\xc2d sdsdfdslkfsdkfjdsf
I see
\xc2d
[]
d\xa0
[]
\xe7
[]
\xc3\ufffdd
[]
\xc3\ufffdd
[]
\xc2\xa0
[]
\xc3\xa7
[]
\xa0\xa0
[]
'619d813\xa03697'
[]