Simple Regex Tutorial

Learn regular expressions one tiny step at a time with 10 practical examples. Each one builds on the last, so you can master regex slowly and confidently!

1. Exact Match

Concept: Literal characters. This matches the exact word "cat". Use it to find a specific word in text.

cat

2. Matching Digits

Concept: Digit character \d. This matches any single digit (0-9). Use it to find numbers in text.

\d

3. Matching Multiple Digits

Concept: Quantifier +. This matches one or more digits in a row. Use it to find numbers like years or prices.

\d+

4. Matching Letters

Concept: Letter range [a-z]. This matches any lowercase letter. Use it to find letters in text.

[a-z]

5. Matching Letters or Digits

Concept: Character set [a-z0-9]. This matches any lowercase letter or digit. Use it to find parts of usernames or codes.

[a-z0-9]

6. Matching Two Options

Concept: Alternation |. This matches "yes" or "no". Use it to find specific choices in text.

yes|no

7. Matching at the Start

Concept: Start anchor ^. This checks if a string starts with "Hi". Use it to validate greetings or headers.

^Hi

8. Matching at the End

Concept: End anchor $. This checks if a string ends with "bye". Use it to validate closings or file extensions.

bye$

9. Matching Whole Words

Concept: Word boundary \b. This matches "cat" as a whole word, not inside "catalog". Use it for exact word searches.

\bcat\b

10. Matching a Simple Pattern

Concept: Combining basics. This matches a code like "A123" (letter then 3 digits). Use it to validate short IDs.

[A-Z]\d{3}

Try changing the text in each example and click "Test" to see how the regex works. Have fun learning!