A regular expression, or regex, is a pattern that describes text: “\d{4}” means four digits in a row, and “^ERROR” with the m flag means a line that starts with ERROR.
This tester uses JavaScript (ECMAScript) regular expressions, the engine built into your browser, so the results are what new RegExp, match, replace and split give in JavaScript. They are not guaranteed to be the same in PCRE, Python, Java or .NET.
The flags
g finds every match instead of only the first. i ignores case. m makes ^ and $ match at the start and end of every line. s lets . match line breaks. u reads the pattern as Unicode code points and enables escapes such as “\u{1F680}”. v is a newer Unicode mode with set operations in character classes, available depending on your browser. y (sticky) matches only where the last match ended. d records where each group starts and ends; the results table shows these ranges.
JavaScript is not PCRE, Python or Java
In JavaScript, possessive quantifiers such as “a++” and atomic groups such as “(?>a)” are syntax errors. Named groups are written “(?<name>…)”; Python's “(?P<name>…)” is an error. Without the m flag, $ matches only at the very end of the text, not before a final line break as in Python and PCRE. And \d matches only the ASCII digits 0 to 9, even with the u flag. Lookbehind and newer syntax work depending on your browser.
Catastrophic backtracking
Some patterns take exponential time when a match fails. In “(a+)+$”, the inner and outer + can divide a run of a's in a huge number of ways, and when the text doesn't end in a, the engine tries every one of them before giving up. Against forty a's followed by “!”, that would freeze a page for a very long time, and each extra a roughly doubles the work.
This tool runs every pattern in a background worker and stops it after 2 seconds, so the page stays usable and your pattern and text are kept. The fix is usually to remove nested repetition: “a+$” finds the same matches at once.
Limits
Test strings can be up to 1,000,000 characters and patterns up to 5,000. Matching stops after 10,000 matches, with a notice. Above 100,000 characters, press Run.
How to use
- Type the pattern between the slashes; you don't add the slashes yourself.
- Tick the flags you need and paste the test string. Matches are highlighted as you type.
- Choose Match, Replace or Split, then copy the results, or the JavaScript code that reproduces them.
Features
- Every match with its start and end index, and every capture group by number and name.
- Replace and Split use JavaScript's own replace and split, so the preview is what your code gets.
Common uses
- Checking log lines. Find every line with a given status code or error ID.
- Extracting IDs from responses. Pull order numbers or UUIDs out of an API response.
- Validating input formats in tests. Try a format against valid and invalid samples before it goes into an assertion.
- Search and replace in test data. Preview a replacement with groups, such as reordering the parts of a date, before running it over a fixture.
Frequently asked questions
What do the flags mean?
Each flag changes how the pattern runs; “The flags” above explains all eight, g, i, m, s, u, v, y and d.
Why does my pattern match nothing, or too much?
Check the flags first: without g only the first match counts, and without m, ^ and $ apply to the whole text. Too much usually means a greedy quantifier: “.*” runs to the end of the line, while “.*?” stops as early as it can.
What is a capture group?
A part of the pattern in parentheses whose text is kept, numbered from 1, or named with “(?<name>…)”. Groups appear in the results table, and in Replace mode as $1 or $<name>.
How do I match a literal dot or another special character?
Put a backslash before it: “\.” matches a dot. The same works for * + ? ( ) [ ] { } ^ $ | and the backslash itself.
Why does the tool say the pattern took too long?
The run went past 2 seconds, usually because of catastrophic backtracking, explained above. The tool stopped it and kept your pattern and text, so you can change them.
Are my text and pattern uploaded?
No. Everything runs in your browser, and nothing you type is sent or saved. Like the rest of the site, the page records a visit when it loads, but not what you enter.
Why do emoji indices look strange?
JavaScript counts positions in UTF-16 code units, and an emoji takes 2 of them, so a match right after one emoji starts at index 2. The u flag doesn't change that; it changes what . and classes match.
Need to test a whole website, not just a snippet?
RoboQA tests real pages and user journeys in a browser: logins, forms, clicks and full flows. See what RoboQA can test or compare plans.