The subject of regular expressions is quite deep, and it takes an immense amount of practice to get used to the special character syntax. Furthermore, the re module contains a vast set of methods available for performing searches using regular expressions. Upon completing the examples in this section, you should have a much deeper appreciation for how powerful regular expressions can be.
Finding Patterns in Text
The most common use for
re is to search for patterns in text. The
search() function takes the pattern and text to scan, and returns a
Match object when the pattern is found. If the pattern is not found,
Match object holds information about the nature of the match, including the original input string, the regular expression used, and the location within the original string where the pattern occurs.
end() methods give the indexes into the string showing where the text matched by the pattern occurs.