What it does
- The pattern runs line by line in this browser's JavaScript regex engine (no flags, or
i) and the matched parts are highlighted. - How
grep -E(GNU's POSIX ERE) andgrep -P(PCRE2) read the same pattern is not emulated — it is diagnosed with a rule table. Only when every piece of the pattern is known to behave the same in all three does the tool say “same lines as JavaScript”; a piece that is read differently is named with the reason, and an unknown piece gives “cannot tell”. - Lines with non-ASCII characters are marked
?when the pattern uses\w,., ranges or-i, because the engines can treat them differently.
Examples
| Pattern | JavaScript | grep -E | grep -P |
|---|---|---|---|
\d+ | digits | one or more letters d — different | digits — same |
[[:digit:]] | one of [ : d i g t, then ] | a digit | a digit |
(?<=GET )/\S+ | look-behind | no look-behind — different | same |
a{,2} | the text a{,2} | a 0 to 2 times | text in 10.42, 0 to 2 times from 10.43 |
x(ab)+?y | ab at least once | (ab)+ becomes optional, so xy matches too | same |
\y | the letter y | the letter y | error unrecognized character follows \ |
How the check was made
Before release 95 patterns were run over a 63-line test text (digits, tabs, backslashes, braces and non-ASCII such as é, ü and emoji). All 179 verdicts matched GNU grep 3.11 with PCRE2 10.42 on the server (LC_ALL=C.UTF-8): “same” means every line matched or not exactly as grep did, “different” means grep really matched a different set of lines, “error” means grep exited with status 2. The 11 “cannot tell” verdicts were not counted. The JavaScript results equalled node's RegExp in 95 of 95 patterns.
Common mistakes
grep -E '\d'— GNU grep -E has no\d; it looks for the letterd. Use[0-9]or[[:digit:]].grep -E '\t'— the lettert, not a tab. In bash usegrep -P '\t'orgrep $'\t'.[[:space:]]in JavaScript — no error, just an unexpected set of characters.- Expecting
.*?to be lazy ingrep -E— ERE has no lazy quantifiers.
FAQ
Can grep -P on my machine differ from this tool?
Some syntax depends on the PCRE2 version ({,n}, variable-length look-behind). The tool only says “same” for rules confirmed with GNU grep 3.11 and PCRE2 10.42 and marks version-dependent syntax as “cannot tell”. grep -V and pcre2test -C show what is installed.
Why not compute the grep result directly?
An imitation of ERE or PCRE inside the browser can give wrong results that look right. So only JavaScript, whose real engine is here, is run; grep line results are shown only when they are known to equal JavaScript.
Is the pattern or the text sent to a server?
No. Everything is calculated in your browser and nothing is written to the address bar. The input is not passed to the visitor statistics or the ads this site uses. Details are on the privacy page.