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.
| Syntax | Meaning |
|---|---|
. | Any character except a line break (any character at all with the s flag) |
\d \w \s | A 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 |
^ $ \b | Start of the text, end of the text (of each line with m), a word boundary |
(…) (?:…) (?<name>…) | Capture group, non-capturing group, named group |
a|b | Either 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.