How to find a pattern from a text file?
Patterns are words or numbers found from a file when required using regex library from python. Below is the snippet which will help us find that.
Here, the word ‘phone’ appears twice in the text and span() gives the location of the index where the word appears. To find all the matches we use findall () method to find out the total number of matches.