Regex basics and common patterns you can test right away
A regular expression (regex) describes a text pattern in a short expression so you can find or replace it. Filtering error lines in a log, checking whether input looks like an email, reformatting dates in bulk: each takes only a few characters. The symbols look cryptic at first, but a handful covers most everyday tasks.
Core symbols
| Symbol | Meaning | Example |
|---|---|---|
. | Any single character | a.c matches abc, a1c |
\d | One digit | \d\d matches 07, 42 |
\w | Letter, digit or underscore | \w+ matches user_1 |
\s | One whitespace character | space, tab, line break |
[abc] | One of the listed characters | [A-Z] is one capital letter |
* + ? | 0 or more, 1 or more, 0 or 1 | \d+ is one or more digits |
{n,m} | Repeat n to m times | \d{3,4} |
^ $ | Start and end of a line | ^\d+$ is a digits-only line |
( ) | Group and capture | Reusable in replacements |
To match a symbol literally, such as ., ? or (, put a backslash in front of it. A literal dot is \..
Common patterns
- Digits only:
^\d+$ - US phone number (555-123-4567):
\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4} - ISO date (2026-11-11):
\d{4}-\d{2}-\d{2} - Email (rough check):
[\w.+-]+@[\w-]+(\.[\w-]+)+ - US ZIP code:
^\d{5}(-\d{4})?$
Formats with complex rules, like email, are hard to validate perfectly with regex. Use the pattern above to filter things that roughly look like an email, and confirm real addresses with a verification email.
Build it while testing
- Paste real sample data into the test text box of the Regex Tester below.
- Write the pattern piece by piece and watch the highlighted matches.
- Check captured groups in the group table.
- Preview replacements using
$1,$2in the replace box.
Flags worth knowing
- g: find all matches, not just the first.
- i: ignore upper and lower case.
- m: make
^and$work on every line of multiline text.
Replacement example: changing a date format
Search for (\d{4})-(\d{2})-(\d{2}) and replace with $2/$3/$1, and 2026-11-11 becomes 11/11/2026. Groups are numbered in the order of their opening parentheses.
Regex syntax differs slightly between programming languages. This tool uses JavaScript rules, so double-check in your target language before using a pattern elsewhere.