EthicalFusion

Regex Tester

Test regular expressions against sample text and see matches.

Was this tool helpful?

Thanks for the feedback!

Type a regular expression in the Pattern box, paste sample text below it, and this regex tester lists every match it finds. It uses your browser's JavaScript regex engine, so the results are what String.match() would return in front-end code or Node.js.

How the pattern box is read

Enter the bare pattern only, such as \d+. Do not wrap it in slashes or add flags: the text is passed straight to new RegExp(), so typing /\d+/g would search for a literal slash, digits, another slash and the letter g, and usually report "No matches." The global flag is always switched on, which means every match in the text is found, not just the first. Case-insensitive (i) and multiline (m) flags are not available, so ^ and $ refer to the start and end of the whole input.

After you click Test regex, the result shows the count, for example "4 match(es):", followed by each match on its own line. Up to 200 matches are printed. A pattern with a syntax error is reported as "Invalid regex:" with the browser's explanation, such as "Unterminated group".

Worked examples

PatternSample textMatches
\d+Order 1042 shipped on 12/03, invoice 881042, 12, 03, 88
\b[1-9]\d{5}\bPIN 110001, 560034 and 4000012110001, 560034
[A-Z]{5}[0-9]{4}[A-Z]PAN: ABCDE1234F and abcde1234fABCDE1234F

The second row is a quick check for six-digit Indian PIN codes, which never start with 0; the word boundaries \b stop it from matching six digits inside the seven-digit number. The third follows the PAN card layout of five letters, four digits and one letter, and it skips the lowercase copy because matching is case-sensitive.

Quick syntax reference

  • \d digit, \w letter, digit or underscore, \s whitespace, . any character except a line break
  • * zero or more, + one or more, ? optional, {2,4} between two and four times
  • [abc] one of the listed characters, [^abc] anything except them
  • ( ) group, | either/or, \b word boundary
  • Escape special characters with a backslash: \. matches a real full stop

Things that surprise people

  • Groups are not listed separately. (\w+) (\d{6}) on "Mumbai 400001" returns the whole match, not the city and PIN as separate captures.
  • Empty matches appear as blank lines. A pattern that can match nothing, such as a*, reports a match at every position where it finds zero characters.
  • Quantifiers are greedy. <.+> grabs from the first < to the last > on a line; add a question mark (<.+?>) to stop at the first closing bracket.
  • No case-insensitive switch. Use character classes such as [Ii]nvoice when capitalisation varies.

To pull every address out of a document without writing a pattern, the Email Extractor is quicker, and the URL Extractor does the same for links.

Frequently asked questions

Why does /\d+/g find nothing?
The pattern box expects the expression without slashes or flags. Type \d+ on its own; the global flag is added automatically.
Can I make the match case-insensitive?
There is no flag option, so list both cases in a character class, for example [Pp]aid, or convert the sample text to one case before testing.
Which regex flavour does this use?
JavaScript (ECMAScript) regular expressions as implemented by your browser. Most PCRE, Python or Java patterns work, but possessive quantifiers and atomic groups are not supported.
How do I see what a capture group matched?
Only whole matches are listed. Narrow the pattern so the entire match is the part you need, for example \d{6} instead of (\w+) (\d{6}).
Is there a limit on the number of matches?
The count covers every match, but only the first 200 are printed in the result box.

Related tools

Embed this tool on your site

Paste it into any blog or website. Free, with a credit link.