Python重新从字符串中找到一个特定的单词

时间:2017-03-18 02:58:49

标签: python

我想从以下字符串中找到所有单词'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']

1 个答案:

答案 0 :(得分:2)

该字符串在这些行的末尾包含换行符和空格。删除它们,然后使用您的命令处理字符串:

s = ''.join([line.rstrip() for line in myString.splitlines()])
re.findall('quick', s, re.M)