DNS Checker.eu

Regex Tester

This regex tester runs a JavaScript regular expression against sample text live, listing every match, its capture groups and position, with flag toggles and a replacement preview - all in your browser.

1 match

#MatchAtCapture groups
1hello@example.fr27hello | example.fr

About Regex Tester

Type a pattern, paste the text you are actually dealing with, and the match table updates on every keystroke: the matched substring, its zero-based index in the subject, and each capture group. A separate field previews a replacement, so you can see what a substitution would produce before running it against a file or a log pipeline. The usual alternative is a throwaway script and several iterations; this collapses that loop onto one screen, and the text you paste never leaves your browser.

JavaScript regular expressions are defined by ECMA-262, and they are not the same language as POSIX ERE, PCRE or Go's RE2. The flags are where most surprises live: a dot does not match a newline unless s is set, ^ and $ only anchor per line with m, and without u a pattern iterates over UTF-16 code units rather than code points, so an emoji or a composed accent can be cut in half. Nested quantifiers bring a worse failure mode, backtracking exponentially on input that ultimately fails to match and turning a harmless-looking pattern into a denial of service.

The tester builds a real RegExp from your pattern and iterates it with matchAll, adding the global flag internally for the match list so you always see every hit, and capping the list at 200 entries so a runaway pattern cannot freeze the page. The replacement preview uses your flags exactly as set, so a substitution without g changes only the first match, as it would in your code. Invalid patterns surface the engine's own error text rather than a generic message, and everything executes locally on the same family of engine as your JavaScript.

How to use it

  1. 1Type your pattern between the slashes; the active flags are shown after the closing slash.
  2. 2Toggle the g, i, m, s and u flags with the pills below the pattern field.
  3. 3Paste the text you want to match into the Test string box.
  4. 4Read the match table for each match, its position in the subject and its capture groups separated by pipes.
  5. 5Enter a replacement using $1 and $2 for group references to see the substituted text under After replacement.
  6. 6If the pattern is invalid, read the engine's error message in the red box and fix the syntax.

Common use cases

  • -Building a log-parsing pattern against a real sample line before committing it to a Logstash or Vector pipeline.
  • -Checking that a validation pattern accepts the awkward inputs it will meet, such as an internationalised domain or a plus-addressed mailbox.
  • -Working out why an existing pattern matches too much, by seeing the greedy match listed with its position.
  • -Drafting a search-and-replace across a configuration file and previewing the result with $1 group references before applying it.
  • -Testing how a pattern behaves with and without the s and m flags to understand multiline matching.

Frequently asked questions

How do I test a regular expression online?
Paste the pattern together with a representative sample of the text it will meet, then read the matches rather than trusting the pattern to be right. This tester lists every match with its position and capture groups as you type, and previews a replacement. Because it runs in your browser, the sample can be real log lines or customer data without being uploaded anywhere.
What does the g flag do in a JavaScript regex?
g makes the pattern iterate over the subject and return every match instead of stopping at the first, and it changes the behaviour of methods that track lastIndex. In a replacement, g is what turns a single substitution into a replace-all. This tester applies g internally when listing matches, so the list is complete, but honours your flags exactly in the replacement preview.
What is catastrophic backtracking in a regex?
It is the exponential blow-up that happens when nested or overlapping quantifiers force the engine to try an enormous number of ways to match a string that ultimately fails, the classic shape being (a+)+$. Applied to attacker-controlled input, a pattern of that form becomes a denial of service, often called ReDoS. Remove the ambiguity, anchor the pattern, or bound the repetition explicitly.
Why does my regex work here but not in grep or PHP?
Because they are different dialects. JavaScript follows ECMA-262; grep uses POSIX basic or extended syntax, PHP and nginx use PCRE, and Go's RE2 refuses backtracking constructs entirely. Escaping rules, lookbehind support, named group syntax and Unicode handling all differ. This tester uses the browser's own engine deliberately, so what you see is what JavaScript will do - verify separately for other languages.