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 ...

Access this course and 1400+ top-rated courses and projects.