Toolpuffin

Regular Expressions for Beginners: The Patterns You Will Actually Use

Updated October 2026

A regular expression (regex) is a short pattern that describes text. It can find every number in a document, check a date format, or clean up spaces. The syntax looks cryptic, but a handful of symbols cover most everyday jobs.

Try it as you read

Open the regex tester, paste some text and type the patterns below. Matches are highlighted as you type, which is the fastest way to learn.

The building blocks

SymbolMeaningExample
\dOne digit\d\d matches 42
\wA letter, digit or underscore\w+ matches a whole word
\sA space, tab or line break\s+ matches any run of spaces
.Any character except a line breakc.t matches cat and cut
+One or more of the previous\d+ matches 7 and 2026
*Zero or more of the previousab*c matches ac and abbbc
?Optional (zero or one)colou?r matches color and colour
{n}Exactly n times\d{4} matches a year
[abc]One of these characters[aeiou] matches a vowel
^ and $Start and end of the text (or line)^Hello matches only at the start
( )A group you can read back(\d+)-(\d+) captures two numbers
|Orcat|dog matches either

Patterns for common jobs

  • All numbers: \d+
  • A date like 2026-10-14: \d{4}-\d{2}-\d{2}
  • Extra spaces: \s{2,}
  • A simple email address: [\w.+-]+@[\w-]+\.[\w.-]+
  • Empty lines: ^\s*$ (turn on the multiline flag)

These are practical patterns, not perfect ones. A real email address can be stranger than any short pattern allows, so use regex to find candidates and not to prove that an address exists.

Use a pattern to replace text

Patterns become more useful together with replacing. Put part of the match in a group, then use $1 for that part in the replacement. For example, find (\d{4})-(\d{2})-(\d{2}) and replace with $3/$2/$1 to turn 2026-10-14 into 14/10/2026.

The flags

  • g finds all matches instead of only the first.
  • i ignores upper and lower case.
  • m makes ^ and $ work on every line.
  • s lets the dot match a line break.

Common mistakes

  • Forgetting to escape a dot. A dot means any character, so write \. to match a real full stop.
  • Greedy matching. .* takes as much as it can, so <.*> matches from the first < to the last > on a line. Use .*? to take as little as possible.
  • Expecting the same behavior everywhere. Languages differ in small details, such as lookbehind support. This tester uses the JavaScript engine of your browser.

Privacy

The pattern and your text are processed in your browser and are not sent anywhere, so you can test on real logs or documents.

More guides