liminfo

GRE Word Reference

Free web tool: GRE Word Reference

Regex Tester

Test JavaScript regular expressions with real-time matching and group capture.

About GRE Word Reference

The Regex Tester is a free, browser-based tool for writing, debugging, and testing JavaScript regular expressions in real time. You supply a pattern string and optional flags (g for global, i for case-insensitive, m for multiline, s for dotAll), paste or type a test string, and the tool instantly executes the regex against your input using JavaScript's native RegExp engine. Every match is highlighted in yellow directly within the test string display, making it immediately obvious what the pattern is capturing.

Developers, data analysts, QA engineers, and students learning regex use this tool to prototype and verify patterns before embedding them in code. Unlike running regex in a browser console, the tester provides a clean visual output showing the total match count, each match's text, its zero-based character index in the string, and the contents of every numbered capture group. This makes debugging complex patterns with multiple capture groups — like parsing email addresses, log entries, or structured data formats — much more efficient.

Technically, the tool uses JavaScript's RegExp.exec() in a loop (when the global flag is set) to collect all matches, then reconstructs the original string with match/non-match segment boundaries to render the highlighted view. Invalid regex patterns display a descriptive error message from the JS engine rather than crashing. All processing happens entirely client-side with no network requests.

Key Features

  • Real-time regex execution using the native JavaScript RegExp engine
  • Match highlighting in the test string — matched segments shown in yellow
  • Separate inputs for pattern and flags (g, i, m, s, u supported)
  • Total match count displayed above the highlighted result
  • Per-match detail panel showing match text, character index, and capture group values
  • Numbered capture group display for patterns with parentheses (group 1, group 2, ...)
  • Descriptive error display for invalid regex syntax without page crash
  • Fully client-side — no data sent to any server, instant results on every keystroke

Frequently Asked Questions

What regex flags does this tester support?

The tester supports standard JavaScript regex flags: g (global — find all matches, not just the first), i (case-insensitive matching), m (multiline — ^ and $ match start/end of each line), s (dotAll — the . metacharacter matches newlines), and u (Unicode mode). Enter them in the Flags field, for example "gi" for global case-insensitive matching.

How do capture groups work in the results?

Capture groups are the parenthesized sub-patterns in your regex, such as (\w+) or (\d{4}). For each match, the tool shows the full match text plus the value captured by each group. Group 1 is the first set of parentheses, Group 2 is the second, and so on. If a group did not participate in the match, its value shows as "undefined".

Why does the tester show "undefined" for a capture group?

A capture group shows "undefined" when it is part of an alternation and the branch containing it did not match. For example, in the pattern (a)|(b), if "b" matched, then Group 1 is undefined and Group 2 is "b". Optional groups using ? can also be undefined when they match zero times.

How do I match across multiple lines?

Use the m (multiline) flag to make ^ match the start of each line and $ match the end of each line. Use the s (dotAll) flag to make the . metacharacter match newline characters in addition to other characters. Combine them as "ms" in the flags field to match patterns that span multiple lines.

Why does my pattern with the g flag go into an infinite loop?

Infinite loops can occur with patterns that can match an empty string (like a*, \s*, or .*) when using the global flag, because after each zero-length match the regex engine does not advance. The tester handles this by incrementing lastIndex after a zero-length match, which prevents the loop from hanging.

How do I test an email address regex pattern?

Enter a pattern like [\w.+-]+@[\w-]+\.[\w.-]+ in the Pattern field, set the flag to "g" to find all emails, and paste a body of text into the Test String field. The tool will highlight every email address it finds and list each one with its position in the text.

Can I use lookahead or lookbehind assertions?

Yes. JavaScript supports positive lookahead (?=...), negative lookahead (?!...), positive lookbehind (?<=...), and negative lookbehind (?<!...). These are zero-width assertions, meaning they match a position without consuming characters. The tester uses the native JS engine so all standard ES2018+ regex features including named capture groups (?<name>...) are supported.

Is this tool suitable for testing regex in Node.js or backend JavaScript?

Yes, because the tester uses the same V8 JavaScript engine that powers Node.js. Patterns that work here will behave identically in Node.js. However, regex behavior can differ between programming languages — Python re, Java java.util.regex, and PCRE have different syntax and feature sets than JavaScript RegExp.