How to write a Python regular expression to use re.findall()?

PythonServer Side ProgrammingProgramming

The re.findall() helps to get a list of all matching patterns. It searches from start or end of the given string. If we use method findall to search for a pattern in a given string it will return all occurrences of the pattern. While searching a pattern, it is recommended to use re.findall() always, it works like re.search() and re.match() both.

Example

import re
result = re.search(r'TP', 'TP Tutorials Point TP')
print result.group()

Output

TP
raja
Published on 10-Jan-2018 14:11:51
Advertisements