DevToolsHub

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
SymbolDescriptionExample patternMatches (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"
\bWord boundary (between word \w and non-word).\bcat\b"cat" as whole word, not "category"
\BNot a word boundary.\Bcat"cat" inside a word, e.g. "vacation"
Character classes
SymbolDescriptionExample patternMatches (idea)
.Any single character except newline (with s flag, includes newline).a.c"abc", "a1c" — not "a\nc"
\dDigit 0–9.\d{3}"123" — three digits in a row
\DAny non-digit.\D+runs of letters/symbols between numbers
\wWord character: letter, digit, or underscore.\w+"foo", "x_1"
\WNon-word character (spaces, punctuation).\Wspace, comma, @, etc.
\sWhitespace (space, tab, newline, etc.).\s+one or more spaces/tabs
\SNon-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)
SymbolDescriptionExample patternMatches (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
SymbolDescriptionExample patternMatches (idea)
( )Capturing group; remembers match for \1, \2….(\w+)\s+\1repeated 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
SymbolDescriptionExample patternMatches (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
SymbolDescriptionExample patternMatches (idea)
\nNewline character.line\nlinetwo lines separated by newline
\tTab.\t+one or more tabs
\\Backslash in pattern (in JS string often "\\").C:\\UsersWindows-style path segment
Flags (checkboxes above)
SymbolDescriptionExample patternMatches (idea)
gGlobal — find all matches, not just the first./\w+/gevery word in the string
iIgnore case — A equals a./hello/i"Hello", "HELLO"
mMultiline — ^ and $ match each line.^#start of every line
sDotAll — . matches newline too..*entire block including line breaks
uUnicode mode — correct handling of surrogate pairs, \u{…}.with u flagfull Unicode code points, not half-pairs

How to use

  1. Enter your pattern (JavaScript regex syntax).
  2. Toggle flags: g for all matches, i for case-insensitive, m for multiline ^/$, s for dotAll, u for Unicode.
  3. Paste text in Test string to see highlighted matches and a match table.
  4. Use Multiple test strings to validate one pattern against many lines.
  5. Share URL copies a link with your pattern and sample text encoded.
  6. 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

Frequently asked questions

Which regex flavor does this use?
JavaScript regular expressions (similar to many browsers and Node.js). Features like lookbehind depend on your browser version.
What are global and case-insensitive flags?
Global (g) finds all matches, not just the first. Case-insensitive (i) ignores letter case. Multiline (m) changes how ^ and $ behave with line breaks.
Why does my pattern hang the browser?
Catastrophic backtracking on nested quantifiers can cause ReDoS. Simplify the pattern or test with shorter strings first.
Can I test multiple lines?
Yes. Add multiple test strings to see how the pattern behaves across different inputs, including edge cases that should not match.
Should I use regex to parse HTML?
No. Use an HTML parser. Regex is for tokens, log lines, and constrained formats—not arbitrary markup.