>>> line = '\xc2d sdsdfdslkfsdkfjdsf'
>>> pattern_strings = ['\xc2d', '\xe9']
>>> pattern = '|'.join(pattern_strings)
>>> pattern
'\xc2d|\xe9'
>>> import re
>>> re.findall(pattern, line)
['\xc2d']
ファイルに入れline
て同じ正規表現を実行しようとすると、何も表示されません
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)
path
次のようなファイルはどこにありますか
\xc2d sdsdfdslkfsdkfjdsf
そうですか
\xc2d
[]
d\xa0
[]
\xe7
[]
\xc3\ufffdd
[]
\xc3\ufffdd
[]
\xc2\xa0
[]
\xc3\xa7
[]
\xa0\xa0
[]
'619d813\xa03697'
[]