Literals
Lesson 7 of 28 in Coddy's RegEx in Python course.
Literal characters are the simplest form of regex patterns. They match exactly what you type.
Let's see a basic example using literal characters:
import re
text = "I have 2 apples and 3 bananas."
pattern = "apples"
matches = re.findall(pattern, text)
print(matches) # Output: ['apples']In the above example, the pattern apples matches the exact word "apples" in the string text.
We've already seen this pattern in previous lessons
Try it yourself
This lesson doesn't include a code challenge.
All lessons in RegEx in Python
1Introduction
Introduction3Basic Pattern Syntax
Basic MetacharactersLiteralsCharacter ClassesRangesCommon Predefined ClassesAdvanced Predefined Classes