Fuji Komalan
Fuji Komalan

Reputation: 2047

Python re.findall a specific word from a string

I want to find all the words 'quick' from the following string.

myString = ''' hi quick is qui
ck is some thing is very big and quick is
it has got some backend quic
k 
'''

my code.

In [39]: re.findall('quick',myString , re.M)
Out[39]: ['quick', 'quick']

Upvotes: 0

Views: 189

Answers (1)

Mayazcherquoi
Mayazcherquoi

Reputation: 474

The string includes newline characters and whitespace at the end of those lines. Remove them, and then process the string using your command:

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

Upvotes: 2

Related Questions