Tech / Regex Tester
Regex Tester
Test a JavaScript regular expression against your text with live highlighting, capture groups and a replace preview. Includes a quick cheat sheet.
Test text
Matches highlighted
Match details
| # | Match | Position | Groups |
|---|
Replace
Cheat sheet
. any character\d digit 0-9\w letter, digit or _\s space, tab, newline\D \W \S NOT digit / word / space[abc] a, b or c[^abc] not a, b or c[a-z] range^ $ start / end\b word boundary* 0 or more+ 1 or more? 0 or 1{2,5} 2 to 5 times*? +? as few as possiblea|b a or b( ) capture group(?:) group, no capture(?<n>) named group\1 repeat group 1(?=) followed by(?!) not followed by(?<=) preceded by\p{L} any letter (u flag)Useful patterns for Australian data
These patterns check the format only - they cannot tell whether a phone number or ABN really exists. Remove spaces before testing phone numbers, and use the m flag when you test one value per line.
| Checks | Pattern |
|---|---|
| Mobile number, such as 0412345678 or +61412345678 | ^(?:\+61|0)4\d{8}$ |
| Postcode (4 digits) | ^\d{4}$ |
| ABN, such as 51 824 753 556, with or without spaces | ^\d{2} ?\d{3} ?\d{3} ?\d{3}$ |
| Email address (a rough check) | ^[^\s@]+@[^\s@]+\.[^\s@]+$ |
An ABN also has a check digit, which a pattern cannot test - look it up on the ABN Lookup website to be sure.
What is catastrophic backtracking?
Some patterns, such as ^(a+)+$, can take an enormous time on text that almost matches, because the regex engine tries every possible way to split the text. On a server this can be used to slow a website down - an attack called ReDoS. This page runs patterns in the background and stops after 1.5 seconds, so try ^(a+)+$ on a long row of a's ending in "b" to see the warning. In your own code, avoid repeated groups inside repeated groups, and limit the length of input before you test it.
The flags
g- find every match, not just the first.i- ignore upper and lower case.m- make^and$work on each line.s- let.match new lines too.u- full Unicode support, needed for\p{L}to match letters in Malayalam and other scripts.
Your patterns and text are tested in your browser and are not uploaded.