我想使用regex迭代所有进程,但我不知道如何正确执行。
import csv
import re
matched_dynamic_pattern = []
matched_static_pattern = []
not_matched = set()
with open('processes.csv', 'r') as t1, open('dynamic_patterns.csv', 'r') as t3:
commands = set()
reader = csv.DictReader(t1, dialect='excel', delimiter=',')
for row in reader:
commands.add(row['Command Line'])
dynamic_patterns = set(t3.read().splitlines())
for command in commands:
for pattern in dynamic_patterns:
if re.search(pattern, command): #MY PATTERN IS NOT WORKING FROM dynamic_patterns.csv
matched_dynamic_pattern.append(command)
else:
if command not in dynamic_patterns:
not_matched.add(command)
dynamic_patterns.csv
只包含一个正则表达式:r'"C:\ProgramsFiless(xdd)\Google\Chrome\Application\chrome.exe"s--type'
,它应该与processes.csv
中的"C:Program Files (x86)GoogleChromeApplicationchrome.exe --type
匹配但是会有很多regex,我不知道如何在技术层面上制定解决方案。
上面的正则表达式示例不起作用。我认为有一个错误的";在接近尾声的模式中。
下面用";C: \Program Files(x86(\Google\Chrome\Application\Chrome.exe--type">
"C:\ProgramsFiless(xdd)\Google\Chrome\Application\chrome.exes--type
在regexr 上测试
你还有图案的例子吗?