Member-only story
Regex Tutorial — A Quick Cheatsheet by Examples
4 min readFeb 9, 2025
Regular expressions (regex) are like special search patterns that help you find and work with text. Think of them as a super-powered way to search through text, kind of like the “Find” feature in your text editor, but much more powerful. In this guide, we’ll learn regex through simple examples that you can try right away.
What is Regex?
Regex is a set of characters that create a search pattern. It’s used in:
- Finding text patterns
- Replacing text
- Validating text (like checking if an email address is written correctly)
- Extracting information from text
Basic Patterns
1. Simple Text Matching
The most basic way to use regex is to find exact text:
pattern = "hello"
# This will find the word "hello" in text
For example, this will match:
- “hello world”
- “say hello to everyone”
- “hello123”
2. Special Characters
Some characters have special meanings in regex:
.
(dot) - matches any single character except newline