我为reddit bot获取了这段代码:
match = re.findall(r"(?i)\bword1\b|\bword2\b|\bword3\b", comment.body)
匹配几个单词。如何打印匹配的单词?
答案 0 :(得分:1)
看看这个例子。这可能会对你有所帮助
import re
f=open('sample.txt',"w")
f.write("<p class = m>babygameover</p>")
f.close()
f=open('sample.txt','r')
string = "<p class = m>(.+?)</p>"
pattern = re.compile(string)
text = f.read()
search = re.findall(pattern,text)
print search