Regex Tester: Online JavaScript Regex Checker

Test a regular expression with every match highlighted, capture and named groups, and a live replace preview. Free, no sign-up, and it runs in your browser.

//g
Type the pattern without the surrounding slashes. Use \d, not \\d.
Flags
g global · i ignore case · m multiline · s dotAll · u unicode · v unicode sets · y sticky · d match indices
$1 numbered group · $<name> named group · $& whole match · $$ a literal $
–
Matches highlighted
Replace result

Matching runs in a background worker and is stopped after 0.5 s, so a runaway pattern cannot freeze the page. Nothing you type is uploaded.

Match details

#PositionMatchCapture groups

Common regex patterns

Click a pattern to load it with sample text. They are practical patterns, not full validators.

How this regex tester works

This tester uses your browser's own JavaScript RegExp engine, the same one your front-end code and Node.js use, so a pattern that works here behaves the same in String.prototype.match, matchAll, replace and test. Each time you type, the pattern is compiled with the flags you ticked and run against the test string. Matches are highlighted, listed with their start and end positions, and every capture group is shown, both numbered and named.

Everything happens on your device. The pattern and text are never sent anywhere, which matters when you are testing against log lines, customer data or API keys.

Worked example: named groups and replace

The default pattern finds ISO dates and names each part: \b(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])\b. On the sample text it finds 2 matches. The first is 2026-10-20 at position 9, with year = 2026, month = 10 and day = 20. The text 2026-13-01 is skipped because the month group only allows 01–12.

With the replacement $<day>/$<month>/$<year> the result becomes: Released 20/10/2026, patched 03/11/2026. Not a date: 2026-13-01. Named references like $<day> are easier to read than $3 and keep working if you add another group later.

Backreferences work inside the pattern too. \b(\w+)\s+\1\b with the gi flags finds a word followed by the same word, and replacing with $1 turns This is is a test of the the repeated word finder. into This is a test of the repeated word finder..

What the flags do

g (global) finds every match instead of stopping at the first. Without it, replace changes only the first match: replacing \d+ with # in “a1 b22 c333” gives “a# b22 c333”, while with g it gives “a# b# c#”.

i ignores case. m (multiline) makes ^ and $ match at the start and end of every line, which is what you want when testing a list of values one per line. s (dotAll) lets . match newlines too.

u (unicode) treats emoji and other characters outside the Basic Multilingual Plane as one character, enables \p{…} property escapes such as \p{L} for any letter, and makes the parser strict about invalid escapes. v (unicodeSets) is the newer version of u (ES2024): it adds set operations in character classes like [\p{L}--[a-z]]. You cannot combine u and v. The v box is hidden if your browser does not support it.

y (sticky) only matches starting exactly at lastIndex, which is useful for writing tokenizers. d (indices) records the start and end of each capture group; the positions appear in square brackets in the match table.

Regex syntax quick reference

These are the building blocks you will use most often. Everything in this table works in the tester above, and in any modern browser or Node.js.

SyntaxMeaning
.Any character except a line break (any character at all with the s flag)
\d \w \sA digit, a word character (letter, digit or _), a whitespace character. Capitals (\D, \W, \S) mean the opposite
[abc] [^abc] [a-z]One character from the set, one character not in the set, one character in the range
* + ?Zero or more, one or more, zero or one of the item before
{3} {2,5} {2,}Exactly 3, between 2 and 5, 2 or more
*? +? {2,5}?Lazy versions: match as few characters as possible
^ $ \bStart of the text, end of the text (of each line with m), a word boundary
(…) (?:…) (?<name>…)Capture group, non-capturing group, named group
a|bEither a or b
(?=…) (?!…) (?<=…) (?<!…)Lookahead, negative lookahead, lookbehind, negative lookbehind
\1 \k<name>Backreference to a numbered or named group

To match one of the special characters . * + ? ^ $ { } ( ) | [ ] \ / literally, put a backslash in front of it: \. matches a real dot, \( a real bracket. Inside a character class most of them lose their meaning, so [.] also matches a dot.

Greedy and lazy quantifiers

Quantifiers are greedy by default: they take as much text as they can and give characters back only if the rest of the pattern fails. That is why <.+> on <b>bold</b> and <i>italic</i> finds 1 match, the whole line from the first < to the last >. Adding ? makes the quantifier lazy: <.+?> stops at the first possible > and finds 4 separate tags.

A negated class is often better than a lazy quantifier. <[^>]+> finds the same tags, cannot run past a closing bracket, and does less backtracking. Regular expressions are fine for quick searches in HTML, but use a real HTML parser when you need to process markup reliably.

Lookahead and lookbehind

Lookarounds check what comes before or after a position without including it in the match. (?<=\$)\d+(?:\.\d{2})? finds amounts that follow a dollar sign but leaves the sign out: on “Total $42.50, tax $3.40, order 1234” it matches 42.50 and 3.40, and skips the order number.

Negative lookarounds match only when something is not there. q(?!u) with the gi flags finds a q that is not followed by u: in “Iraq, quit, Qatar” it finds 2 matches, the q in Iraq and the Q in Qatar. JavaScript supports lookbehind of any length, which some other flavours restrict, and all current major browsers support it.

Matching a whole string versus part of it

A regex matches if the pattern is found anywhere in the text, so \d{5} matches inside “ZIP 941035” (1 match: 94103) even though that is six digits. To check that the entire input has a given format, anchor both ends: ^\d{5}$ matches “94103” but not a longer string. When you validate a list with one value per line, tick m as well, so ^ and $ apply to each line.

Catastrophic backtracking and the 0.5 second limit

JavaScript uses a backtracking regex engine. Patterns with nested or overlapping quantifiers, such as (a+)+$ or (\w+\s?)*$, can take exponentially longer as the input grows when there is no match, because the engine tries every way of splitting the text between the quantifiers. On a server this is a denial-of-service risk (ReDoS); in a browser it freezes the tab.

This tester runs matching in a Web Worker and stops it after 500 milliseconds, then tells you the pattern is too slow. To fix a slow pattern, make each repeated part match something the next part cannot: \w+(?:\s\w+)* instead of (\w+\s?)*, and prefer specific classes like [^"]* over .*.

JavaScript regex tips and gotchas

Escaping in strings. In a regex literal you write /\d+/, but in new RegExp("\\d+") the backslash must be doubled because the string is parsed first. Enter patterns here as you would write them between slashes.

Reusing a global regex. A regex with g or y keeps its lastIndex between calls, so calling test() twice on the same object can alternate between true and false. Use matchAll, or reset lastIndex.

Differences from PCRE and Python. JavaScript supports lookahead, lookbehind, named groups and Unicode property escapes, but not possessive quantifiers, atomic groups, \A/\Z or recursion. Inline modifiers are only supported in recent browsers, and only in the scoped form (?i:…). A pattern copied from another language may need small changes.

Validation patterns are approximations. The email and URL patterns in the library catch typos, but the only real test of an email address is sending a message to it. If you are moving config between formats, our YAML to JSON converter validates the syntax for you, and the Markdown to HTML converter turns README files into clean HTML.

Using your pattern in JavaScript code

Once a pattern works here, copy it between slashes into your code with the same flags. The common methods are: re.test(str) for a yes/no answer; str.match(re) for the first match with its groups (or every match text with g); str.matchAll(re), which requires the g flag, to loop over every match with its groups; str.replace(re, replacement) and replaceAll to substitute; and str.split(re) to split on a pattern.

The replacement can also be a function, which receives the match and its groups and returns the new text, useful when the new text needs a calculation. When you build a pattern from user input with new RegExp(), escape the special characters first, or a search for “1+1” will be read as a pattern. Newer engines provide RegExp.escape() for this; where it is missing, the MDN guide shows a short escape function.

Sources and further reading

This page describes standard JavaScript behaviour as documented in the MDN regular expressions guide and the ECMAScript language specification (RegExp objects). The v flag is explained by the V8 team in RegExp v flag with set notation, and the risks of slow patterns in the OWASP article on ReDoS.

Regex Tester: frequently asked questions

Which regex flavour does this tester use?

It uses the JavaScript RegExp engine built into your browser, so results match what you get in JavaScript and Node.js. Other flavours such as PCRE (PHP), Python re and Java are similar but not identical; for example JavaScript has no possessive quantifiers or atomic groups.

How do I use capture groups in the replacement?

Use $1, $2 and so on for numbered groups, $<name> for a named group written as (?<name>...), $& for the whole match, and $$ for a literal dollar sign. Without the g flag only the first match is replaced, exactly as in String.prototype.replace.

Why does my regex only find one match?

Without the g (global) flag JavaScript stops after the first match. Tick the g box to find every match. If you use ^ and $ to match whole lines in a multi-line list, also tick m (multiline), otherwise ^ and $ only match at the very start and end of the text.

Why did the tester stop with a timeout warning?

Your pattern took longer than 0.5 seconds, which almost always means catastrophic backtracking caused by nested or overlapping quantifiers such as (a+)+ or (.*)*. Rewrite the pattern so each repeated part cannot match the same characters in more than one way.

What is the difference between the u and v flags?

Both turn on full Unicode mode, so emoji count as one character and property escapes like \p{L} work. The v flag (unicodeSets, added in ES2024) also allows set subtraction and intersection inside character classes and is stricter about some characters. The two flags cannot be used together.

Can I test Python, Java or PHP regex here?

Mostly, yes. This regex tester runs the JavaScript engine, and the core syntax (character classes, quantifiers, groups, anchors and lookahead) works the same in Python, Java, PHP and .NET. Differences show up in the details: Python writes named groups as (?P<name>...), JavaScript has no possessive quantifiers or atomic groups, and lookbehind support varies. Test the basics here, then confirm edge cases in your own language.

How do I match a special character such as a dot or a bracket?

Put a backslash in front of it. \. matches a literal dot, \? a question mark and \( an opening bracket. Without the backslash a dot matches any character, so a pattern like example.com also matches examplexcom. Inside square brackets most special characters are literal, so [.] works too.

What is the difference between greedy and lazy matching?

A greedy quantifier such as .+ takes as many characters as it can, then backs off only as far as needed. A lazy quantifier such as .+? takes as few as possible. On text with several tags, <.+> matches from the first tag to the last one, while <.+?> matches each tag separately.

How do I make a regex match the whole string, not just part of it?

Add ^ at the start and $ at the end. Without anchors the pattern can match anywhere, so \d{5} finds five digits inside a longer number. With ^\d{5}$ the whole input must be exactly five digits. If you test one value per line, also tick the m flag.

Does JavaScript support lookbehind?

Yes. Positive (?<=...) and negative (?<!...) lookbehind are part of the language and work in all current major browsers and in Node.js. Unlike some other flavours, JavaScript allows lookbehind patterns of variable length.

Is my test data sent to a server?

No. The pattern and test text are processed entirely in your browser by a background script on this page. Nothing is uploaded or stored, so it is safe to test against logs or other private data.