๐ Regex Tester & Cheatsheet
Test regular expressions in real-time with a built-in cheatsheet. Highlight matches, view capture groups. Flags: g, i, m, s.
๐ When to Use the Regex Tester
Developers test regular expressions before pasting them into validation code โ write a pattern for email, phone, or URL validation, throw sample data at it, and see which inputs match and which don't. Backend engineers extract structured data from logs by building a regex and watching capture groups fill with timestamps, IP addresses, and error codes in real time. Data analysts clean CSV or JSON exports by testing find-and-replace patterns before running them on production data. Students learning regex use the live feedback to understand how quantifiers (*, +, ?), character classes ([a-z]), and anchors (^, $) behave โ tweak the pattern and see the effect instantly. The cheatsheet (toggle with "Show Cheatsheet") provides a quick reference for common regex syntax without leaving the tool.
โ๏ธ How the Regex Tester Works
The tester uses JavaScript's built-in RegExp engine โ the same regex implementation that powers every browser and Node.js. Your pattern and flags are passed to new RegExp(pattern, flags), and the .exec() method loops through the test text with a while loop, collecting match positions, full strings, and capture groups from mt.slice(1). Without the g (global) flag, the loop stops after the first match. Supported flags: all valid JavaScript flags are accepted โ g (global), i (case-insensitive), m (multiline: ^ and $ match line starts/ends), s (dotAll: . matches newlines), u (Unicode mode), y (sticky), and d (hasIndices). Flags are combined in a text field (e.g., "gim"). Matches are highlighted inline in the test text using <mark> tags with a red background, and listed below with positions and capture groups (first 5 matches shown to keep output readable). Errors: invalid patterns display the browser's native SyntaxError message in red โ fix your pattern and the error clears instantly. A toggleable cheatsheet provides a static reference for common regex tokens (\d, \w, [a-z], quantifiers, anchors). All processing uses input event listeners; typing in any field triggers immediate recalculation. No CDN libraries, no API calls โ pure JavaScript RegExp running locally in your browser.
How to Use the Regex Tester
1. Enter your regex pattern. Type a regular expression into the "Regex Pattern" field. Use flags like g (global), i (case-insensitive), m (multiline), and s (dotAll) in the flags input to control matching behavior.
2. Provide test text. Paste or type the text you want to test against in the "Test Text" area. The tool comes with sample text showing capitalized words, so you can see the default pattern [A-Z][a-z]+ in action.
3. See real-time results. Matches are highlighted and listed immediately as you type. Each match shows the full matched string, its position (index), and any capture groups extracted from the match.
4. Iterate and debug. Tweak your pattern and flags, add or remove test text, and watch the matches update live. If your pattern has a syntax error, the tool displays it so you can fix it.
Frequently Asked Questions
What regex flags are supported?
The tester accepts all standard JavaScript regex flags: g (global โ find all matches, not just the first), i (case-insensitive โ "A" matches "a"), m (multiline โ ^ and $ match start/end of each line, not just the whole string), s (dotAll โ . matches newline characters too), u (Unicode โ enables \p{...} property escapes and correct surrogate pair handling), y (sticky โ match must start at lastIndex), and d (hasIndices โ adds start/end positions to match results). Enter flags as a combined string in the flags field, e.g., gim.
How are capture groups displayed?
Each match shows an array with the full match at position 0, followed by each capture group in order. For example, pattern (\d+)-(\d+) against "123-456" shows [0]: "123-456", [1]: "123", [2]: "456".
Why aren't my matches showing up?
Check that you've entered the g flag for multiple matches. Without it, only the first match is returned. Also verify your pattern syntax โ the tester validates your regex and shows error messages for invalid patterns.
Is my test data sent anywhere?
No. All regex testing happens entirely in your browser using JavaScript's built-in RegExp engine. Your patterns, test text, and match results are processed locally and never leave your device. The cheatsheet is static HTML โ no network requests are made for regex functionality.
What regex flavor/syntax does this use?
This tester uses JavaScript (ECMAScript) regex syntax โ the same engine built into every browser and Node.js. It is similar to PCRE (Perl-Compatible Regular Expressions) but has important differences: lookbehind ((?<=...) and (?<!...)) is supported in Chrome 62+ and Node.js 9+ (ES2018), but not in older browsers. Unicode property escapes (\p{Letter}) require the u flag and ES2018+. JavaScript does not support possessive quantifiers (*+, ++), \A/\Z anchors (use ^/$), or named character classes like [[:digit:]]. If you're porting a regex from Python, Perl, or PHP, test it here first to catch syntax differences.
Does it support find-and-replace?
No โ this is a tester, not an editor. It shows matches, capture groups, and positions so you can verify your pattern works, but it does not perform replacement. For find-and-replace with regex, use your code editor's replace function (VS Code, IntelliJ), the sed command line tool, or JavaScript's String.prototype.replace() in the browser DevTools console.