Regex tester (JavaScript)
Test JavaScript regular expressions against your text as you type. Matches and capture groups (numbered and named) are highlighted, with a replace preview and code snippets for JavaScript, Python and PHP.
Engine: JavaScript (ECMAScript) RegExp in your browser
Regular expressions in PCRE (PHP), Python, Java and other engines differ in syntax and behavior. If you use the pattern elsewhere, test it there too.
Enter a pattern to see the matches here.
The result is long, so only the first 1,000,000 characters are shown.
| # | Index | Length | Match | Groups |
|---|
Use it in code
How to use
- Type the pattern without the surrounding slashes and choose flags such as g, i and m.
- Enter the test string. Matches are highlighted, and the count, index and groups of each match are listed.
- To try a replacement, turn on "Show replace preview" and enter a replacement string ($1, $<name>, $& and so on).
- Under "Use it in code", pick JavaScript, Python or PHP to copy a snippet that uses the pattern.
- Pick a sample (dates, email addresses, URLs and more) to see an example.
Notes and limits
- The engine is the JavaScript (ECMAScript) RegExp of your browser. PCRE (PHP), Python, Java, .NET and other engines differ in syntax and behavior, so a result here is not guaranteed to be the same elsewhere.
- The v flag is offered only when your browser supports it.
- A search that does not finish within 1.5 seconds is stopped (protection against catastrophic backtracking from patterns such as (a+)+$). Safari (JavaScriptCore) may give up on such a search by itself and report no match.
- Test strings up to 200,000 characters. Up to 10,000 matches are collected; the list shows the first 200 and the first 1,000 are highlighted.
- Indexes are counted in UTF-16 units, as in JavaScript, so an emoji can count as 2.
- Code snippets are a starting point. The Python and PHP versions convert syntax such as named groups, but not every difference.
How it works
Matching runs in a Web Worker, separate from the page. If it takes too long, the worker is terminated, so the page never freezes. "Cancel" stops it at any time.
With the g flag every match is found; without it only the first. After an empty match the search moves on by one character (one code point with u or v).
Group positions come from the d flag (hasIndices) and are drawn nested inside each match. Nothing is inserted as HTML; all text is shown as plain text.
FAQ
Will the result be the same in PHP or Python?
Not necessarily. This tool runs on the JavaScript engine of your browser. The basics are shared, but lookbehind, Unicode handling, the meaning of $ and other details differ. Test in your target language as well.
Are my pattern and text sent anywhere?
No. Everything runs in your browser and nothing is sent or stored.
Why was the search stopped?
Patterns with nested quantifiers such as (a+)+$ can take exponential time on text that does not match (catastrophic backtracking). Rewrite the pattern, for example by removing the nested quantifier.
Related tools
Last updated: