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
| Pattern | Sample text | Matches |
|---|---|---|
\d+ | Order 1042 shipped on 12/03, invoice 88 | 1042, 12, 03, 88 |
\b[1-9]\d{5}\b | PIN 110001, 560034 and 4000012 | 110001, 560034 |
[A-Z]{5}[0-9]{4}[A-Z] | PAN: ABCDE1234F and abcde1234f | ABCDE1234F |
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
\ddigit,\wletter, digit or underscore,\swhitespace,.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,\bword 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]nvoicewhen 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.