Regex Tester
Enter a pattern, pick flags, paste your test string: the regex tester shows every match with its index, the contents of numbered and named capture groups and explains each part of the pattern in plain English. Matching uses your browser’s JavaScript engine (ECMAScript).
How it is calculated
This regex tester uses the JavaScript flavor of regular expressions as defined by the ECMA-262 standard and implemented by your browser. A pattern that works here works exactly the same in String.prototype.match, matchAll, replace and RegExp.prototype.test – in Chrome, Firefox, Safari and Node.js.
Reading the result
- Matches: every match with its index (zero-based character position, counted in UTF-16 code units as JavaScript does – an emoji counts as 2) and length. Line breaks are shown as ↵, tabs as ⇥.
- Groups per match: what each pair of parentheses captured – numbered groups
( )and named groups(?<name> ). “Did not participate” means the group sits in an alternative that wasn’t taken. With thedflag you also get the position of each group. - Pattern explained: every token in plain English; indented rows (›) are inside a group.
The flags
g finds all matches instead of just the first, i ignores case, m makes ^ and $ work per line, s lets the dot match line breaks. u treats emoji and other characters outside the Basic Multilingual Plane as one character and enables Unicode properties such as \p{L} (any letter, including é or ñ). v is the newer version of u with set operations like [\p{L}--[a-z]]; u and v can’t be combined. y (“sticky”) only finds matches that follow each other without gaps.
Protection against infinite loops and hangs
Patterns such as a* or \b can produce empty matches. Like JavaScript itself, the tester then advances by one character (a full code point with u/v), so there is no infinite loop. At most 1,000 matches are searched for.
The bigger danger is catastrophic backtracking (ReDoS): nested quantifiers like (a+)+$ try an exponential number of combinations on a string that doesn’t match – 30 characters can keep the engine busy for minutes. That’s why the search runs in a separate background thread and is stopped after 2 seconds; the page stays responsive. Avoid such patterns in your own code too, especially on user input.
Differences from other regex flavors
PCRE (PHP), Python, Java and .NET differ in the details: JavaScript has no possessive quantifiers (a++), no atomic groups and no \A or \Z anchors; \w only covers A–Z, a–z, 0–9 and the underscore – for accented letters use \p{L} with the u flag.
Your test string is not sent, not stored and not written into the link – only the pattern and the flags are.
Frequently asked questions
How do I test a regular expression?
Type the pattern without slashes into the top field, tick the flags you need and paste your text. All matches are highlighted in the text straight away and listed with their index; below that you see what each group captured.
Why doesn’t \w match accented letters?
In JavaScript, \w only stands for A–Z, a–z, 0–9 and _. For letters in any language, use \p{L} with the u flag, e.g. [\p{L}\d_]+ for a word such as “café”.
What is the difference between greedy and lazy?
Greedy quantifiers (*, +, {2,}) take as much text as possible, lazy ones with a trailing question mark (*?, +?) as little as possible. On “<b>x</b>”, <.+> matches the whole string, <.+?> only “<b>”.
How do I name a capture group?
Use (?<name>…). In code you read it via match.groups.name, in a replacement string with $<name>, and inside the pattern with the backreference \k<name>.
Why was my search stopped?
It took longer than 2 seconds – usually because of catastrophic backtracking with nested quantifiers such as (\w+)*. Simplify the pattern: don’t nest quantifiers, make alternatives unambiguous and anchor it with ^ and $.
Does the result also apply to PHP or Python?
For simple patterns it usually does, but it is only guaranteed for JavaScript. PHP (PCRE) and Python support extra syntax such as possessive quantifiers or \A, and Python traditionally writes named groups as (?P<name>…).
Sources and legal basis
- ECMA-262 § 22.2: ECMA-262 – ECMAScript Language Specification, RegExp (Regular Expression) Objects
- MDN Web Docs – Regular expressions (Guide)
- MDN Web Docs – RegExp.prototype.flags
- MDN Web Docs – String.prototype.matchAll() (empty matches, lastIndex)
- OWASP – Regular expression Denial of Service (ReDoS)
As of:
Related tools
- JSON formatter, validator and minifierValidate JSON against RFC 8259 with the exact line, column and a plain-English explanation. Beautify or minify, sort keys, copy. Runs locally in your browser.
- XML and CSV validator onlineCheck XML for well-formedness and validate CSV against RFC 4180: errors with line and column, auto-detected delimiter, table preview. Runs locally.
- Base64 Encode and DecodeEncode and decode Base64 and Base64url with proper UTF-8, plus URL encode/decode (percent-encoding). Clear error messages, runs locally in your browser.
- Hash Generator: SHA-256, SHA-512, SHA-1, MD5Calculate SHA-256, SHA-384, SHA-512, SHA-1 and MD5 hashes of text or files and verify checksums – locally in your browser, no upload, free.
- Validate Email Address SyntaxCheck one or many email addresses for correct syntax under RFC 5321/5322: lengths, domain labels, international domains (Punycode). Local, nothing sent.
- Aspect Ratio CalculatorCalculate the aspect ratio from width and height (1920 × 1080 = 16:9), find the missing side, decimal value, nearest standard ratio and CSS aspect-ratio.