How to test a regular expression
- Type your pattern in the box between the two slashes, for example
\d{3}-\d{4}. Enter only the pattern: the slashes are already drawn for you, so typing your own would make them part of the pattern. - Pick the flags you need (g is on by default) and paste your test text below. If the pattern is invalid, the engine's own error message appears in red.
- Matches are highlighted instantly, with a numbered list showing each match, its starting index and the value of every capture group. Copy matches copies the matched text, one match per line.
Understanding the flags
The four flags offered are: g (global) finds every match instead of stopping at the first; i (ignore case) treats A and a the same; m (multiline) makes ^ and $ anchor to the start and end of every line, not just the whole string; and s (dot all) lets . also match newline characters. You can combine them freely, and the active flags are shown after the closing slash. The tool does not offer the u (unicode), y (sticky) or d flags, which matters for the Unicode note below.
Worked examples
- Phone fragments:
\d{3}-\d{4}onCall 555-0142 or 555-0199gives two matches, at index 5 and index 17. - Capture groups:
(\d{4})-(\d{2})-(\d{2})on2026-10-07gives one match with$1=2026,$2=10,$3=07. - Greedy vs lazy: on
<b>bold</b>the pattern<.+>matches the entire string as one match, because.+grabs as much as it can. Changing it to<.+?>makes the quantifier lazy and finds two matches,<b>and</b>. - Lines with m: with the m flag on,
^\w+matches the first word of every line. Without m it matches only the first word of the whole text.
Capture groups
Anything you wrap in parentheses becomes a capture group. For example, (\w+)@(\w+) matched against an email captures the user part as group 1 and the domain part as group 2. The match list shows $1, $2 and so on for each match, and a group that did not take part in the match, such as one inside an unused alternative, shows as undefined. Named groups written as (?<year>\d{4}) work, but are listed by number in this tool.
JavaScript flavor: differences from other languages
- Use
^and$for the start and end of the text.\Aand\Zfrom other languages do not mean that in JavaScript. - Python-style named groups
(?P<name>…)are invalid; JavaScript uses(?<name>…). - Possessive quantifiers and atomic groups, found in PCRE and Java, do not exist in JavaScript.
- Without the
uflag, Unicode property escapes such as\p{L}do not work as property classes, and emoji or other characters outside the basic plane are treated as two units. If you need those, test the same pattern in your target environment.
Common mistakes
- Forgetting to escape special characters. A literal dot must be
\.; an unescaped.matches any character, so1.5also matches125. - Forgetting the g flag and wondering why only one match is found.
- Catastrophic backtracking. Nested quantifiers such as
(a+)+$against 30 letters a followed by a single!can take billions of steps. This tester runs on the page's main thread with no timeout, so such a pattern can freeze the tab until the browser gives up. Test risky patterns on short inputs first, and avoid nested repetition of the same characters in production code. - Typing escape sequences in the test box. The test string is raw text, so typing
\nthere inserts a backslash and the letter n, not a line break. Press Enter to create a real newline.
Limits of this tool
Matching stops at 5,000 matches, and only the first 300 appear in the numbered list, although the highlighted text shows everything found. A zero-length match, such as \b or ^, is drawn as a thin bar. There is no replace or substitution preview, so check your replacement string in your own code.
Is it private and safe?
Yes. Toolyard runs the regular expression inside your browser on your own device using the built-in JavaScript engine. Your pattern and test text are never uploaded anywhere, which makes it safe for log files, code snippets and private data.
Related guides
See the step-by-step guide to testing a regular expression, learn how backslashes work in JSON escape characters, or use the URL encoder when your matches need to go into a link.
Frequently asked questions
Which regex syntax does this tester use?
JavaScript (ECMAScript) regular expressions, using the same engine your browser uses, which is also what Node.js uses in most setups. Most common syntax carries over to other languages, but features like possessive quantifiers, atomic groups, \A and Python-style named groups differ.
What do the g, i, m and s flags mean?
g finds all matches instead of just the first, i makes matching case-insensitive, m makes ^ and $ match at every line, and s lets the dot match newline characters. The u, y and d flags are not available in this tool.
Why does my pattern match only once?
The g flag is probably off. Without it, JavaScript stops after the first match. Tick g and every match in the text will be highlighted and listed.
Why is the page freezing on my pattern?
Most likely catastrophic backtracking, where nested quantifiers like (a+)+$ make the engine try an exponential number of paths on certain inputs. Shorten the test text, remove the nested repetition or make the groups more specific. The tool has no timeout, so you may need to close the tab if it hangs.
Does it support Unicode, emoji and \p{L}?
Not fully. Without the u flag, which this tool does not provide, property escapes like \p{L} are not interpreted as Unicode classes and characters outside the basic plane count as two units. Plain accented letters work normally if you list them or use a character range.
Can it do find-and-replace?
No. It shows matches, their positions and capture groups, but not a replaced result. Once your pattern is right, use it with replace() in your own code and use $1, $2 for the groups.
Is my text uploaded anywhere?
No. The pattern and test text are processed entirely in your browser. Nothing is uploaded, so it is safe for logs and private data.
Is it free?
Yes, completely free with no sign-up. It will highlight up to 5,000 matches and list the first 300.