A regular expression, or regex for short, is simply a sequence of characters that specifies a certain search pattern. Regular expressions have been around for quite a while and are a field of computer science in and of themselves.
In Python, regular expression operations are handled using Python's built in re
module. In this section, I will walk through the basics of creating regular expressions and using them to You can implement a regular expression with the following steps:
- Specify a pattern string.
- Compile the pattern string to a
regular expression
object. - Use the
regular expression
object to search a string for the pattern. - Optional: Extract the matched pattern from the string.