Back to tools

Regex Tester

Test JavaScript regular expressions before they ship

Regular expressions are the most compact way to validate input, extract data, and transform text, yet a single misplaced metacharacter silently changes what a pattern matches. A regex that looks correct can pass every happy-path test and then fail on a trailing newline, a nested quote, or a string with an unexpected Unicode character. This tester runs your pattern in the JavaScript flavor with configurable flags and shows the complete match list, so you can see exactly what a pattern captures before it lands in production code.

You need it whenever you write form validation, parse log lines, scrub sensitive data, or build a search filter. Testing against real sample text beats reasoning about the pattern in your head, and seeing every match — not just the first one — reveals greedy and global-flag surprises early.

How to Test a Pattern Step by Step

  1. Open the Regex Tester and type your pattern, such as \b\d{4}-\d{2}-\d{2}\b for a date.
  2. Choose the flags you need: g for all matches, i for case-insensitive, m for multiline anchors, s so the dot matches newlines, and u for Unicode-aware matching.
  3. Paste sample text into the test area and review the highlighted matches and the match list.
  4. Add edge cases — empty strings, extra whitespace, uppercase input, Unicode characters — and re-run.
  5. Copy the final pattern and flags into your code, keeping the literal form for new RegExp(...) or the slash form for a literal.
  6. When a pattern grows beyond a few tokens, test each group in isolation to confirm the captures you rely on.

Real Example: Extracting Email Addresses from a Log

A support log contains mixed-case addresses with trailing punctuation. The pattern [\w.+-]+@[\w-]+\.[\w.-]+ with the g and i flags finds every address, while a first-match-only test would hide the duplicates that indicate repeated login attempts.

InputPatternMatches
Contact: Alice@Example.com; bob@acme.io[\w.+-]+@[\w-]+\.[\w.-]+Alice@Example.com, bob@acme.io
id=42 price=9.99price=\d+\.\d{2}price=9.99 (escaped dot matches a literal period)

Tips for Reliable Patterns

When to Use the Regex Tester

Regex Questions Developers Ask

Which regex flavor does the tester use?

The tester evaluates patterns with the JavaScript regex engine, which is what runs in browsers and Node.js. Features and syntax follow the ECMAScript specification, so results match what your front-end code will do.

What do the g, i, m, s, and u flags do?

The g flag returns every match instead of the first, i ignores case, m makes ^ and $ match at line boundaries, s lets the dot match newlines, and u enables Unicode-aware matching of surrogate pairs.

Why does my pattern match more than expected with the g flag?

Without anchors or word boundaries, a pattern matches every substring that qualifies, including overlapping-looking sequences. Add \b boundaries or tighten the pattern to constrain where matches can start and end.

What is the difference between greedy and lazy quantifiers?

Greedy quantifiers such as .* consume as much as possible, while lazy ones such as .*? consume as little as possible. Lazy quantifiers usually match the intended first occurrence when the surrounding text is variable.

How do I match a literal dot or backslash?

Escape them with a backslash: \. matches a period and \\ matches a single backslash. Inside a JavaScript string literal, each pattern backslash must itself be doubled, so \\d in a string becomes \d in the pattern.

What are lookaheads and lookbehinds?

Lookarounds assert what must follow or precede a position without consuming characters. For example, \d+(?=px) matches digits only when followed by px, and the px itself is not part of the match.

Why do I need double backslashes in JavaScript strings?

In a string literal such as "\d", the backslash starts an escape sequence, so \d becomes just d. Writing "\\d" passes a real \d to the regex engine; a slash literal like /\d/ avoids the problem.

How do I reuse a captured group?

Numbered backreferences like \1 repeat the text captured by the first group, which is useful for matched pairs such as quotes or tags. In a replacement string, use $1 to insert the captured text.