The Matching Characters
Let's discuss how to match characters in the string using regular expressions.
Overview
When we want to match a character in a string, in most cases we can just use that character or that substring.
So if we wanted to match
“dog”, then we would use the letters dog. Of course, there are some
characters that are reserved for regular expressions. These are known as
metacharacters. The following is a complete list of the metacharacters
that Python’s regular expression implementation supports:
. ^ $ * + ? { } [ ] | ( )
Let’s spend a few moments looking at how some of these work.
[ and ]
One of the most common pairs of metacharacters we will encounter are the square braces: [ and ]. They are used for creating a “character class”, which is a set of characters that we would like to match.
We may list the characters individually like this: [xyz]. This will ...