Skip to main content

Foundations of Regular Expressions

Literal Characters and Basic Patterns

0:00
LearnStep 1/3

Matching Literal Strings

Matching Literal Strings

At its core, a regular expression is a pattern describing a set of strings. The simplest pattern is just a sequence of characters that matches itself literally.

In Python, the re module provides methods to perform these matches. The re.search() function scans through a string, looking for the first location where the regular expression produces a match.

python

Case Sensitivity

By default, regular expressions in Python are case-sensitive. This means that the pattern 'Python' will not match the string 'python'.

python

Using re.IGNORECASE

To perform a case-insensitive match, you can pass the re.IGNORECASE flag (or its shorthand re.I) as the third argument to re.search().

python