RegEx Tester

Write a regex pattern and match it against text instantly.

How This Tool Works

Operation: The Regex Tester compiles and executes JavaScript regular expressions using the RegExp constructor and the String.prototype.match() method. When you enter a pattern, the tool creates a new RegExp(pattern, flags) object, handling any syntax errors via try-catch. The tool then applies the regex to your test string using .match(), returning all matches (with the g flag) or the first match with capture groups. Each match is visually highlighted in the test string using a DOM overlay technique — the tool splits the string into text nodes before and after each match, wrapping matches in elements with high-contrast background colours. Match details — full match text, capture group values, index positions, and length — are displayed in a structured results panel beneath the input.

Flags supported: g (global), i (case-insensitive), m (multiline), s (dotall), u (unicode), y (sticky).

Key Benefits of Using the Regex Tester

  • 100% client-side execution: Your regex patterns and test strings — which may include proprietary code, internal API paths, or sensitive log data — are never transmitted to any server. All matching is performed locally by the browser's JavaScript engine.
  • Real-time visual highlighting: As you type or modify your pattern, matched portions of the test string are instantly highlighted with colour-coded backgrounds. Each distinct match group can be colour-coded for easy visual parsing of complex patterns.
  • Comprehensive match details: The results panel shows the full match text, each capture group's value, the numeric index of each match within the string, and match length — providing all the data needed for debugging complex expressions.

Practical Real-World Use Cases

  • Web developers validating form inputs: A developer crafting a regex pattern for email validation (/^[\w.-]+@[\w.-]+\.\w{2,}$/) can test it against dozens of valid and invalid email addresses in real time, ensuring the pattern catches all edge cases before deployment.
  • Data engineers cleaning log files: An engineer parsing server access logs with a pattern to extract IP addresses, timestamps, and request paths can iteratively refine the regex against sample log entries, using highlight feedback to verify each capture group extracts the correct segment.
  • Security researchers analysing payloads: A researcher writing patterns to detect SQL injection attempts (/('|\bOR\b|\bAND\b|--)/i) can test against known attack vectors confidentially — the patterns never leave the local machine.

Frequently Asked Questions (FAQ)

What regex flavour does this tool use?

JavaScript/ECMAScript regex, following the RegExp specification. This is similar to Perl-compatible regex (PCRE) but with some differences — no lookbehind in older browser versions, no possessive quantifiers, and limited Unicode property escapes.

How can I match multiline text?

Enable the multiline (m) flag. This changes the behaviour of ^ and $ anchors to match at the start/end of each line rather than the start/end of the entire string. For the dot to match newline characters, enable the dotall (s) flag.

Why is my pattern not matching anything?

Common causes: missing the global g flag for multiple matches, using lookbehinds ((?<=...)) which aren't supported in all browsers, or escaping characters that don't need escaping. Check the error message below the pattern input for syntax issues.