Free Regex Tester
Enter a regex pattern and test string to see all matches highlighted in real time. Supports flags: global, case-insensitive, multiline.
Matches
Regex Quick Reference
Character Classes
| . | Any character (except newline) |
| \d | Digit [0-9] |
| \D | Non-digit |
| \w | Word char [a-zA-Z0-9_] |
| \W | Non-word char |
| \s | Whitespace |
| [abc] | Any of a, b, or c |
| [^abc] | Not a, b, or c |
Quantifiers
| * | 0 or more |
| + | 1 or more |
| ? | 0 or 1 (optional) |
| {n} | Exactly n times |
| {n,m} | Between n and m times |
| *? | Lazy (match as few as possible) |
Anchors & Groups
| ^ | Start of string/line |
| $ | End of string/line |
| \b | Word boundary |
| (abc) | Capture group |
| (?:abc) | Non-capturing group |
| a|b | a or b |
Try These Common Patterns
Frequently Asked Questions
Which regex flavour does this tester use?
JavaScript's, because it runs in your browser using the native engine. That matters when you are writing a pattern for somewhere else: JavaScript has no possessive quantifiers and no recursion, its lookbehind support arrived later than the rest, and named groups use (?<name>...) syntax. A pattern that works here may need adjusting for PCRE, Python, Go or a database engine, and vice versa.
What is the difference between greedy and lazy matching?
A greedy quantifier takes as much as it can and then gives characters back until the rest of the pattern fits; a lazy one, written with a trailing question mark, takes as little as possible and expands only as needed. Against <b>one</b> and <b>two</b>, the pattern <.+> matches the whole string while <.+?> matches just the first tag. Greedy-by-default is the single most common reason a pattern matches far more than intended.
Why does my pattern match nothing when the text looks right?
Four causes cover nearly all of it. An unescaped metacharacter — a dot, plus, question mark, parenthesis or square bracket — being read as syntax rather than a literal. A missing global flag, so only the first match is found. Case sensitivity, without the i flag. Or invisible characters in the test text: a non-breaking space copied from a document is not matched by \s in every engine, and a trailing carriage return will defeat a pattern anchored with $.
What does the global flag actually change?
It makes the engine continue past the first match instead of stopping, which is what you want for finding or replacing every occurrence. It also makes the regex object stateful in JavaScript: a global regex remembers where it stopped, so reusing the same object across calls can skip matches unexpectedly. That surprise is the reason to build a fresh pattern inside a loop rather than hoisting it out.
Can a regular expression validate an email address?
Not fully, and trying is usually a mistake. The grammar in RFC 5322 permits quoted strings, comments and nested constructs that no practical pattern handles, so a strict regex rejects valid addresses while a loose one accepts unusable ones. The workable approach is a permissive shape check — something before an at sign, something after it with a dot — and then confirmation by sending a message. Only delivery proves an address exists.
What is catastrophic backtracking, and how do I avoid it?
It is when nested quantifiers give the engine an exponential number of ways to fail, so a pattern that is fine on short input hangs on a slightly longer one. Constructs like (a+)+$ are the classic shape. It is the mechanism behind a whole class of denial-of-service bug, so it matters whenever a pattern touches untrusted input. Avoid nesting one quantifier inside another, anchor patterns where you can, and prefer a specific character class to a dot.
How do capture groups and named groups work?
Each pair of parentheses captures what it matched, numbered from left to right, and you read them back as $1 and $2 in a replacement. Naming them with (?<year>\d{4}) makes a pattern far easier to maintain, because renumbering no longer happens when you insert a group. If you need grouping only for alternation or a quantifier and not for capture, use (?:...) — it keeps the numbering clean and is marginally faster.
Is my pattern or test text sent to a server?
No. The pattern is evaluated by your browser's own regex engine, with no network request, no logging and no storage. That is worth knowing because test data is often real data — log excerpts, customer records, tokens — and none of it leaves the page.
Validate Scanned Barcode Data with Regex
The Scan & Generate app gives you raw access to scanned barcode content — perfect for validating formats like ISBN, EAN, or custom codes.