C.W.K.
Stream
Lesson 01 of 12 · published

Literal Characters — The Default

~6 min · literals, fundamentals

Level 0Pattern-Curious
0 XP0/90 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

Most of your pattern is literal

We touched this in Track 1, but it's worth one focused lesson because it's the foundation. Every character in your pattern that isn't one of the 14 metacharacters is a literal character. It matches itself. That's the entire rule.

Pattern hello matches the substring hello. Pattern 2026-05-04 matches the substring 2026-05-04. Pattern The quick brown fox matches the substring The quick brown fox.

Case sensitivity is the default

By default, cat does NOT match Cat or CAT. Almost every engine has a case-insensitive flag — i in JS / PCRE, re.IGNORECASE in Python, (?i) as an inline flag in many flavors. Use it explicitly when you want case-insensitive matching; don't assume it.

Whitespace matches whitespace exactly

A literal space in your pattern matches exactly one space. Three spaces in your pattern require three spaces in the input. If you want "one or more spaces of any kind," you need \s+ (Track 2, lesson 6).

Unicode is mostly transparent

Modern engines handle Unicode literals as you'd expect. Pattern 피파 matches 피파. The complications start when you mix Unicode with case-insensitivity, normalization forms, or shorthand classes — covered later. For literals alone, just type the characters.

Code

Literal matching across cases and whitespace·python
import re

# Case-sensitive by default
re.findall(r'cat', 'Cat scattered cats')
# ['cat']

# Case-insensitive flag
re.findall(r'cat', 'Cat scattered cats', re.IGNORECASE)
# ['Cat', 'cat', 'cat']

# Whitespace is literal: 1 space matches exactly 1 space
re.findall(r'foo bar', 'foo bar  foo  bar')  # double-space breaks it
# ['foo bar']

# Korean literals work transparently
re.findall(r'피파', '피파 안녕 피파')
# ['피파', '피파']

External links

Exercise

Open a regex tester and write three patterns that match a literal email subject like 'Re: Your invoice #1138' — one case-sensitive, one case-insensitive, and one that survives the user typing extra spaces between words. Notice how the third one needs a quantifier you haven't learned yet.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.