Regex Tester
Test patterns against multiple strings with live highlighting so you catch edge cases before shipping validation logic.
Keep both matching and non-matching samples in the same session to spot regressions when you tweak quantifiers.
Matches will appear here.
Regex symbols reference
Each symbol with a short description and example of what it matches.
▸Anchors & boundaries
| Symbol | Description | Example pattern | Matches (idea) |
|---|---|---|---|
| ^ | Start of string (start of each line with m flag). | ^Hello | "Hello" at start of text |
| $ | End of string (end of each line with m flag). | end$ | text ending in "end" |
| \b | Word boundary (between word \w and non-word). | \bcat\b | "cat" as whole word, not "category" |
| \B | Not a word boundary. | \Bcat | "cat" inside a word, e.g. "vacation" |
▸Character classes
| Symbol | Description | Example pattern | Matches (idea) |
|---|---|---|---|
| . | Any single character except newline (with s flag, includes newline). | a.c | "abc", "a1c" — not "a\nc" |
| \d | Digit 0–9. | \d{3} | "123" — three digits in a row |
| \D | Any non-digit. | \D+ | runs of letters/symbols between numbers |
| \w | Word character: letter, digit, or underscore. | \w+ | "foo", "x_1" |
| \W | Non-word character (spaces, punctuation). | \W | space, comma, @, etc. |
| \s | Whitespace (space, tab, newline, etc.). | \s+ | one or more spaces/tabs |
| \S | Non-whitespace. | \S+ | first "word" without spaces |
| [ ] | Any one character inside brackets. | [aeiou] | any single vowel |
| [^ ] | Any character NOT in brackets. | [^0-9] | any char that is not a digit |
| [a-z] | Range inside brackets. | [A-Z][a-z]+ | "Hello" style capital + lowercase |
▸Quantifiers (how many times)
| Symbol | Description | Example pattern | Matches (idea) |
|---|---|---|---|
| * | Zero or more of the previous. | ab*c | "ac", "abc", "abbbc" |
| + | One or more of the previous. | \d+ | "42", "007" — not "" |
| ? | Zero or one (optional). | colou?r | "color" or "colour" |
| {n} | Exactly n times. | \d{4} | exactly 4 digits, e.g. year |
| {n,} | At least n times. | \w{3,} | words with 3+ letters |
| {n,m} | Between n and m times. | \d{1,3} | 1 to 3 digits |
| *? +? ?? | Lazy (non-greedy): as few repeats as possible. | <.*?> | shortest span inside < > |
▸Groups & alternation
| Symbol | Description | Example pattern | Matches (idea) |
|---|---|---|---|
| ( ) | Capturing group; remembers match for \1, \2…. | (\w+)\s+\1 | repeated word: "hi hi" |
| (?: ) | Non-capturing group (grouping only). | (?:https?:)// | "http://" or "https://" |
| | | OR — match left or right side. | cat|dog | "cat" or "dog" |
| (?= ) | Positive lookahead: followed by pattern without consuming. | \d(?=px) | digit only if "px" follows |
| (?! ) | Negative lookahead: not followed by. | \d(?!px) | digit not before "px" |
| (?<= ) | Positive lookbehind (fixed length in some engines). | (?<=@)\w+ | word after @ |
| (?<! ) | Negative lookbehind. | (?<!\$)\d+ | digits not after $ |
▸Escaping & literals
| Symbol | Description | Example pattern | Matches (idea) |
|---|---|---|---|
| \ | Escape special characters to match them literally. | \. | a literal dot, not "any char" |
| \. | Literal period. | file\.txt | "file.txt" |
| \* \^ \$ etc. | Special chars need \ when you want the character itself. | \(\) | literal parentheses |
▸Common escapes
| Symbol | Description | Example pattern | Matches (idea) |
|---|---|---|---|
| \n | Newline character. | line\nline | two lines separated by newline |
| \t | Tab. | \t+ | one or more tabs |
| \\ | Backslash in pattern (in JS string often "\\"). | C:\\Users | Windows-style path segment |
▸Flags (checkboxes above)
| Symbol | Description | Example pattern | Matches (idea) |
|---|---|---|---|
| g | Global — find all matches, not just the first. | /\w+/g | every word in the string |
| i | Ignore case — A equals a. | /hello/i | "Hello", "HELLO" |
| m | Multiline — ^ and $ match each line. | ^# | start of every line |
| s | DotAll — . matches newline too. | .* | entire block including line breaks |
| u | Unicode mode — correct handling of surrogate pairs, \u{…}. | with u flag | full Unicode code points, not half-pairs |
How to use
- Enter your pattern (JavaScript regex syntax).
- Toggle flags: g for all matches, i for case-insensitive, m for multiline ^/$, s for dotAll, u for Unicode.
- Paste text in Test string to see highlighted matches and a match table.
- Use Multiple test strings to validate one pattern against many lines.
- Share URL copies a link with your pattern and sample text encoded.
- Expand Regex symbols reference below the tool for each symbol, description, and example.
1Why test regular expressions in isolation
Regular expressions are dense: a single misplaced quantifier can change whether a pattern matches an entire line or just one character.
A dedicated tester lets you try multiple sample strings at once, which mirrors how real user input varies in length, casing, and spacing.
- Start with the simplest pattern that works, then add anchors (^, $) and boundaries (\b) deliberately rather than all at once.
- Keep examples that should match and examples that should not match in the same session so regressions are obvious when you tweak the pattern.
2Readability and maintenance
Comments and whitespace are not always available in every engine; when they are, use them to document intent for the next developer.
If a regex grows past a few logical clauses, consider parsing with a small state machine or a parser library instead—complexity has a real cost in review time and incident response.
3Performance and safety in apps
Catastrophic backtracking is a real issue in some languages; testing with adversarial strings (long repeats, near misses) can surface risky patterns early.
Never run untrusted regex engines against untrusted input on critical paths without timeouts or sandboxing—ReDoS remains a common web vulnerability class.
4Building patterns incrementally
Start with a literal match, confirm it works, then add character classes, quantifiers, and anchors one at a time. Each addition should have a test string that fails if you remove it—otherwise the clause may be redundant.
Named capture groups improve readability in languages that support them and make replacement strings self-documenting.
5When not to use regex
Parsing HTML, XML, or arbitrary JSON with regex leads to fragile code. Use a DOM parser, XPath, or JSON.parse instead. Regex is appropriate for tokens, log lines, and constrained formats like ISO dates or semver strings.
6Quick checklist for regex changes
Keep at least one string that should match and one that should not. Re-run tests after each small change instead of rewriting the whole pattern at once.
- Watch for catastrophic backtracking on nested quantifiers.
- Prefer explicit character classes over `.` when input can span lines.
Examples
Email-like pattern (simplified)
Production apps should use libraries; this illustrates anchors and character classes.
Pattern: ^[\w.-]+@[\w.-]+\.\w{2,}$
Test: user@example.com ✓
Test: not-an-email ✗Extract semver from a tag
Use a capture group to pull version numbers from git tag strings.
Pattern: v?(\d+\.\d+\.\d+)
Test: release/v1.2.3 → group 1 = 1.2.3