GrepBoardTools GrepBoard manuals ↗ Log ↗

Tools / Text & encoding

Regex tester: JavaScript, grep -E and grep -P

Type a pattern such as \d+ or (?<=GET )/\S+ and paste lines to test.

What you type is calculated only in your browser and is not sent to a server.

Examples

JavaScript (this browser)

—

grep -E (POSIX ERE, GNU)

Read differently

grep -P (PCRE2)

Same lines as JavaScript

Reference: GNU grep 3.11 with PCRE2 10.42, LC_ALL=C.UTF-8. “Same” means the same lines match (grep prints lines); with -o the printed part can still differ.

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) and grep -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

PatternJavaScriptgrep -Egrep -P
\d+digitsone or more letters d — differentdigits — same
[[:digit:]]one of [ : d i g t, then ]a digita digit
(?<=GET )/\S+look-behindno look-behind — differentsame
a{,2}the text a{,2}a 0 to 2 timestext in 10.42, 0 to 2 times from 10.43
x(ab)+?yab at least once(ab)+ becomes optional, so xy matches toosame
\ythe letter ythe letter yerror 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 letter d. Use [0-9] or [[:digit:]].
  • grep -E '\t' — the letter t, not a tab. In bash use grep -P '\t' or grep $'\t'.
  • [[:space:]] in JavaScript — no error, just an unexpected set of characters.
  • Expecting .*? to be lazy in grep -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.