Regex Tester

Test your regular expressions live — matches highlighted, groups shown, replace mode included. No server needed.

Advertisement
/ /
Matches: 0 Groups: 0

Quick patterns:

Advertisement

What Are Regular Expressions?

Regular expressions (regex) are patterns that describe sets of strings. They are used in search engines, text editors, programming languages, and command-line tools to find, validate, and transform text. A regex like \b\d{4}\b matches any standalone 4-digit number. Regex is supported natively in JavaScript, Python, Java, PHP, and virtually every modern programming language.

Common Regex Syntax Reference

PatternMeaningExample
\dAny digit 0–9\d{6} matches 123456
\wWord char (a-z, A-Z, 0-9, _)\w+ matches "hello_1"
\sWhitespace (space, tab, newline)\s+ matches spaces
^ $Start / end of string (or line with m flag)^\d+ matches digits at start
(a|b)Alternation — a or b(cat|dog) matches either
(?:…)Non-capturing group(?:foo)+ matches foofoofoo
(?=…)Lookahead (match if followed by)\d+(?= USD) matches "50"

Regex Flags

g (global) — find all matches, not just the first. i (case-insensitive) — match regardless of letter case. m (multiline) — ^ and $ match start/end of each line. s (dotAll) — dot (.) matches newline characters too. u (unicode) — treat pattern and string as Unicode. Combine flags: gi means global + case-insensitive.

Testing Strategy: Build Incrementally

The most reliable way to build a working regex pattern is incrementally rather than all at once. Start with the simplest fragment that matches your most basic case, verify it against your sample text using the live highlighting above, then progressively add anchors, quantifiers, and groups — re-testing after every single change. Jumping straight to a complex, fully-formed pattern without this step-by-step verification is the most common source of subtle regex bugs, especially around edge cases like empty strings or unexpected special characters.

Understanding Match Highlighting

As you type your pattern, every match in your test string is highlighted directly inline, letting you visually confirm the regex is capturing exactly the text you intend — no more, no less. This is particularly valuable for catching "too greedy" matches, where a quantifier like .+ consumes far more text than intended because it isn't properly anchored or scoped with a more specific character class.

Replace Mode for Bulk Text Transformation

Beyond matching, the Replace mode lets you test find-and-replace operations before running them in production code — substitute matched text (or captured groups, referenced as $1, $2) with new content, and immediately see the transformed output. This is the same operation performed by String.replace() in JavaScript or re.sub() in Python, letting you validate the exact replacement logic against real sample data first.