Regex Tester
Test JavaScript regular expressions with flags and live match highlighting.
What is Regex Tester?
A regex tester is a developer tool that compiles a regular expression, runs it against a sample input string, and highlights every match in place so you can see exactly what the pattern captures and what it misses. The pattern is parsed by the browser’s native ECMAScript RegExp engine, the same engine that runs in production JavaScript, so the results you see in the tester match the results your code will produce at runtime.
QA engineers, frontend developers, and DevOps teams use a regex tester to draft and refine patterns for form validation, log parsing, URL rewriting, and search-and-replace operations. The live highlighting feedback loop catches greedy quantifiers, missed anchors, and case-sensitivity bugs in seconds, long before the pattern lands in a pull request.
Why use this regex tester?
- See matches as you type. Every keystroke recompiles the pattern and re-highlights matches in the test string, so you can tune a quantifier or anchor and watch the result update in real time without clicking Run.
- Catch syntax errors before they ship. Invalid patterns surface a precise error message from the
RegExpconstructor, so a stray unescaped bracket or an unknown flag is flagged before you paste the pattern into production code. - Toggle flags without rewriting the pattern. Buttons for
g,i,m,s, andulet you experiment with global, case-insensitive, multiline, dotall, and Unicode modes without reformatting the pattern itself. - Stay private with sensitive logs. Patterns and test strings run entirely in your browser. Log lines, email addresses, and customer IDs you paste in for testing never leave your device.
- Match the engine in your code. The tester uses native JavaScript
RegExp, so results behave identically in Node.js, Deno, Bun, and every modern browser without dialect differences.
How to use the Regex Tester
- Type or paste your pattern into the Pattern input between the
/slashes. Omit the wrapping slashes themselves. - Click any of the Flags buttons (
g,i,m,s,u) to toggle that flag on or off. The active flags are appended after the closing slash for reference. - Paste the text you want to match against into the Test string textarea below.
- Watch the Matches panel highlight every hit in the test string and show the total match count above the highlighted text.
- If the pattern is invalid, read the inline error message above the test string, fix the pattern, and the highlights will resume.
Regex syntax reference
The tester uses the ECMAScript regex grammar defined in the ECMA-262 specification, section 22.2. The building blocks below cover roughly 90% of real-world patterns.
\d one digit, equivalent to [0-9]
\w one word character, [A-Za-z0-9_]
\s one whitespace character
. any character except newline (use s flag to include newlines)
[abc] one of a, b, or c
[^abc] anything except a, b, or c
[a-z] any lowercase letter
^ start of string (or line, with m flag)
$ end of string (or line, with m flag)
\b word boundary
? zero or one of the previous token
* zero or more
+ one or more
{2,5} between 2 and 5
(abc) capturing group
(?:abc) non-capturing group
(?<name>x) named capturing group
a|b a or b (alternation)| Construct | Matches | Example |
|---|---|---|
\d{3}-\d{4} | A 3-then-4 digit sequence with a hyphen | 555-1234 |
^https?:// | Strings beginning with http:// or https:// | https://shotmark.com |
[A-Za-z][\w.-]*@\w+\.\w+ | A loose email shape | user.name@example.com |
\b\w{5,}\b | Words of five or more characters | regular |
(?<year>\d{4})-(?<month>\d{2}) | Named groups for date parts | 2026-05 captures year=2026, month=05 |
\s+$ | Trailing whitespace on a line (use m flag) | Lines ending in spaces |
Lookahead ((?=...)), lookbehind ((?<=...)), and negated variants ((?!...), (?<!...)) are supported in all current evergreen browsers and Node.js 18+.
Common use cases
- Frontend developers validating form inputs. Draft patterns for phone numbers, postal codes, and license keys, then drop the working regex into a React Hook Form or Zod schema.
- QA engineers parsing log lines. Build a pattern that pulls request IDs or stack-trace markers out of a captured log dump, then reuse it in a grep pipeline.
- DevOps engineers writing nginx and Caddy rules. Test URL-rewrite patterns against real path samples before shipping a config that could break routing in production.
- Backend developers writing search-and-replace migrations. Confirm a pattern only matches the intended fields in a sample export before running it across a database snapshot.
- Tech writers cleaning up imported text. Strip Markdown noise, collapse whitespace, or normalize quotation marks across a documentation import.
Frequently asked questions
Does this regex tester support PCRE?
No. The tester uses the browser’s native ECMAScript RegExp engine, which differs from PCRE in a few areas: ECMAScript has no recursion, no atomic groups, and slightly different character-class shorthands. Most everyday patterns work in both dialects, but features like (?R) or possessive quantifiers (++, *+) will throw a syntax error here.
Why is my pattern matching too much?
Quantifiers are greedy by default, so .* matches as much as it can. Add a ? after the quantifier to make it lazy: .*? matches as little as possible. Adding anchors (^, $, \b) and using more specific character classes ([^"]* instead of .*) also tighten the match.
What does the g flag actually do?
The g (global) flag tells the regex to find every match instead of stopping at the first. The tester always runs in global mode internally so the match list is complete, but the flag is shown in the pattern display when you toggle it on.
Can I use named capture groups?
Yes. Use (?<name>...) to name a group, then read it from the match object as match.groups.name in your code. Named groups are supported in all modern browsers and Node.js 10+. The tester compiles them without warnings.
Why does my Unicode pattern fail?
ECMAScript regex treats Unicode as code units by default, which breaks surrogate-pair characters and Unicode property escapes. Toggle the u flag to enable Unicode mode, then features like \p{Letter}, \p{Emoji}, and proper handling of characters outside the Basic Multilingual Plane work as expected.
How are matches highlighted?
The tester walks the input string, slices it at each match boundary, and wraps matched segments in a <mark> element with a subtle background. Overlapping matches are not possible in ECMAScript regex, so each character belongs to at most one highlight.
Is the pattern stored anywhere?
No. The pattern and test string live only in browser memory while the tab is open. There is no server call, no analytics event, and no autosave to local storage, so patterns containing internal hostnames or sample customer data stay private.
Can I paste a regex with surrounding slashes?
Yes, but you should strip them first. The tester expects the pattern body only. Slashes and flags entered inside the Pattern field are treated as literal characters, not as regex delimiters, which usually causes a syntax error.
Related tools
- Text from Regex. Generate sample strings that satisfy a given pattern for fixture data.
- CSS Validator. Validate CSS syntax and catch unclosed braces before deploy.
- HTML Validator. Check HTML markup against W3C parsing rules.
- Credit Card Validator. Verify card numbers with the Luhn algorithm.
Related tools
ShotMark captures what you do here, in one click.
The traces, payloads, and tests you run by hand? ShotMark grabs the whole bug and hands it to your AI agent.