A regular expression can be used to find all matches in a string or simply test if a match exists.
Regular expressions help you to quickly collect some items from large piles of data just by defining some grammar rules.
Create a string to run the regular expression. As example phrase we’ll use the famous American tongue twister “wouldchuck”.
Find all matches for a string using a regular expression. Call the method findall() with as parameters the regular expression and the search space.
string = "How much wood would a woodchuck chuck if a woodchuck could chuck wood?"
It returns the matches for the regular expression.
We define starting letters “woo”, followed by a word character \w that matches zero or more times * .
Checkout this cheat sheet if you want to write your own regular expressions.