January 2019
Beginner
318 pages
8h 23m
English
This is one of the methods of the match object. The findall() method finds all the matches and then returns them as a list of strings. Each element of the list represents as a match. This method searches for the pattern without overlapping.
Create a re_findall_example.py script and write the following content in it:
import repattern = 'Red'colors = 'Red, Blue, Black, Red, Green'p = re.findall(pattern, colors)print(p)str_line = 'Peter Piper picked a peck of pickled peppers. How many pickled peppers did Peter Piper pick?'pt = re.findall('pe\w+', str_line)pt1 = re.findall('pic\w+', str_line)print(pt)print(pt1)line = 'Hello hello HELLO bye'p = re.findall('he\w+', line, re.IGNORECASE)print(p)
Run the script and you will ...
Read now
Unlock full access