Sunday, October 27, 2019

Python Program to retrieve all words having 5 characters length.


import re
str = 'one two three four five six seven 8 9 10'
result = re.findall(r'\b\w{5}\b' , str)
print(result)


Ouptut:
['three', 'seven']

instead of using the findall() method,
if we use the search() method,
it will return the first occurrence of the result only.

No comments: