How to use
- Enter the pattern between the slashes and choose flags. g finds all matches, i ignores case, m makes ^ and $ work on each line, s lets the dot match line breaks and u turns on Unicode mode.
- Type or paste the text to test. Matches are highlighted as you type, and the list shows each match with its index and groups.
- To preview a replacement, enter a replacement string such as $2-$1 or $<name>. The replaced text appears at the bottom.
Examples
Pattern (\d+)-(?<word>[a-z]+) with flag g on: order 12-apple, order 7-pear and 305-fig
→ 3 matches: 12-apple, 7-pear, 305-figReplacing with $<word>#$1 gives: order apple#12, order pear#7 and fig#305
Pattern a* with flag g on: baac
→ 4 matches: an empty one at 0, aa at 1, and empty ones at 3 and 4A pattern that can match nothing also matches the empty gaps between characters.
Pattern ^\w+ with flags g and m on two lines: one and two
→ 2 matches: one and twoWithout m, ^ would match only at the start of the whole text.
How it works
The pattern and flags are passed to the browser’s own RegExp object, and the matches are collected with String.prototype.matchAll when the g flag is on, or a single exec when it is off. For each match the tool shows the position, the matched text, the numbered groups and the named groups.
The highlighted text is built from plain text pieces, so whatever you paste is displayed as text and never interpreted as HTML. At most 1000 matches are listed.
Matching runs in a Web Worker with a time limit of 2 seconds. If the limit is reached, the worker is stopped and a fresh one is started for the next change, so a slow pattern cannot freeze the page.
Sources
Frequently asked questions
- Which regex flavour does this use?
- The JavaScript one, the same engine your browser runs, so it matches what you get in JavaScript or TypeScript code. Other languages differ in details: PCRE, Python and Java support features JavaScript does not, such as inline flags like (?i) or possessive quantifiers.
- Why was my pattern stopped after 2 seconds?
- Some patterns, such as (a+)+$ on a long string of a followed by another character, make the engine try an exponential number of ways to match, which is called catastrophic backtracking. The tool runs your pattern in a separate worker and stops it after 2 seconds, so the page keeps working.
- What do $1 and $<name> mean in the replacement?
- $1 inserts the text of the first capture group, $2 the second, and so on. $<name> inserts a named group, and $& inserts the whole match. Write $$ for a literal dollar sign.
- Why does replace only change the first match?
- Without the g flag a pattern matches, and replaces, only once. Turn on g to replace every match.
- Is my text uploaded?
- No. Everything runs in your browser and nothing is sent to a server.