我想从以下字符串中找到所有单词'quick'。
myString = ''' hi quick is qui
ck is some thing is very big and quick is
it has got some backend quic
k
'''
我的代码。
In [39]: re.findall('quick',myString , re.M)
Out[39]: ['quick', 'quick']
答案 0 :(得分:2)
该字符串在这些行的末尾包含换行符和空格。删除它们,然后使用您的命令处理字符串:
s = ''.join([line.rstrip() for line in myString.splitlines()])
re.findall('quick', s, re.M)