Regex Tester
Test regular expressions against your own text with live highlighting, capture groups, and a replace preview.
By Alex van den Berg · Last reviewed · How we test our tools
Quick syntax reference
.any character except newline\d \w \sdigit, word char, whitespace* + ?0+, 1+, 0 or 1 of preceding{2,4}between 2 and 4 repetitions^ $start / end of line(...)capture group[abc]character classa|balternation (a or b)How to read and build a regular expression
A regular expression is read left to right as a sequence of instructions, not a single "shape" to memorize. Take an email-matching pattern like [\w.+-]+@[\w-]+\.[\w.-]+: it says "one or more word characters, dots, plus signs, or hyphens" (the local part), then a literal @, then "one or more word characters or hyphens" (the domain name), a literal dot, then "one or more word characters or dots" (the TLD, which allows multi-part domains like .co.uk). Reading it as connected clauses rather than a block of symbols is the fastest way to debug a pattern that isn't matching what you expect.
The biggest practical trap is greediness. By default, quantifiers like * and + grab as much text as possible before backtracking, which can cause a pattern like <.+> to match all the way from the first < to the last > in a line of HTML, instead of stopping at the first tag's close. Adding a ? after the quantifier (<.+?>) makes it "lazy," matching the shortest possible string instead. This tester's live highlighting is the quickest way to see the difference — toggle a quantifier between greedy and lazy and watch which characters get marked.
Regular expressions are also one of the few pieces of syntax that are nearly identical across languages — JavaScript, Python, PHP, and grep/PCRE all share the same core metacharacters (\d, \s, {n,m}, character classes) even though flag syntax and function names differ. A pattern you validate here in JavaScript's engine will very likely work unmodified in Python's re module or a command-line grep -E, which is why testing patterns in an interactive tool before pasting them into a script or config file (like an nginx rewrite rule or a form validator) catches mistakes far cheaper than a failed deploy.
Frequently Asked Questions
What does the 'g' flag do?
The global flag makes the regex find every match in the text instead of stopping after the first one. Without it, only the first match is reported, which also changes how .replace() behaves — it only replaces the first occurrence.
Why isn't my pattern matching anything?
Common causes: forgetting to escape special characters like . or ( that need a backslash to be literal, case sensitivity (add the 'i' flag), or the 'm' flag being needed for ^ and $ to match line boundaries in multi-line text rather than just the start/end of the whole string.
What are capture groups for?
Parentheses in a pattern, like (\d{3})-(\d{4}), create capture groups that extract specific pieces of a match — useful for pulling a username out of an email, or reformatting a date. Each match above lists its captured groups separately from the full match.
What's the difference between greedy and lazy quantifiers?
A greedy quantifier (*, +) matches as much text as it can before backtracking to satisfy the rest of the pattern. A lazy quantifier (*?, +?) matches as little as possible instead. This matters most with wrapping characters like quotes or angle brackets, where greedy matching can accidentally span from the first opening character to the very last closing one in the text.
Will a pattern that works here also work in Python or PHP?
Usually yes for the core syntax — character classes, quantifiers, groups, and anchors are shared across JavaScript, Python's re, PHP's PCRE, and grep -E. Differences show up mainly in flag syntax (JavaScript flags go after the closing slash, Python flags are a separate argument) and a handful of advanced features like named groups' exact syntax, so always do a final test in your target language for anything non-trivial.
Is my text sent anywhere to run this?
No. This uses your browser's native JavaScript regular expression engine. Nothing is uploaded — matching happens instantly and locally as you type.