Regex Interactive Hub
Advanced testing, substitution, code generation, and real-time pattern analysis
See exactly what your regular expression matches
A pattern that looks right often behaves unexpectedly on real input. The Regex Tester runs your expression against a test string and reports back in several ways at once: highlighted text, a list of matches with positions, capture group contents, an optional replacement result and starter code in four languages. It is meant for debugging a pattern before you commit it to a codebase.
Testing a pattern
- Type the expression into Regular Expression Pattern. The slashes shown on either side are decoration, so do not type them.
- Edit Flags. It starts with g, i and m.
- Optionally fill Substitution (Replace with) to preview a replacement.
- Enter text in Test String (Subject). Paste, Sample (a paragraph with three email addresses) and Clear are available.
- Press Execute Regex Analysis.
Reading the output
The stats bar gives the number of matches and the number of capture groups in the first match. Visual Match Highlighting displays your text with matches marked. Under Detailed Matches, each hit is listed with its index position and a table of group contents. Pattern Explanation lists common tokens found in your expression, such as digit shorthand or a capturing group, with plain descriptions. The Implementation Code Generator shows a snippet for JavaScript, PHP, Python or Java depending on the tab you have selected, with your pattern and flags filled in and placeholder text where your data goes.
Where it earns its keep
- Refining an email or date pattern until it matches the good samples and skips the bad ones.
- Checking how many capture groups a pattern produces before referencing them in code.
- Previewing a masking substitution such as replacing addresses with a placeholder.
- Grabbing a working snippet in your language rather than writing the loop from memory.
Know the caveats
The engine is your browser's JavaScript regex implementation, so syntax that JavaScript does not support, such as some PCRE or Python-only constructs, will show an error or behave differently from your target language. The generated PHP, Python and Java snippets are templates and are not run by this page. The Exec Time badge shows a random small number and is not a real performance measurement, so do not use it to compare patterns. The Pattern Explanation only recognises a short list of common tokens, so it will not explain lookarounds or quantifier ranges. Without the g flag, only the first match is reported.
If the expression is invalid, a red message shows the engine error and your text is displayed unhighlighted. Patterns run in your browser, so extremely heavy backtracking on long text can make the tab slow.
Related Tools
Related Tools