Regex Tester
Test regular expressions against sample text with live match highlighting and capture group extraction.
Disclaimer: This tool runs entirely in your browser -- nothing you enter is sent to or stored on our servers.
Regex Syntax Quick Reference
Regular expressions (regex) are patterns for matching, searching, and manipulating text. Core syntax: . (any character), * (0 or more), + (1 or more), ? (0 or 1), ^ (start), $ (end), [] (character class), () (capture group), | (OR). Quantifiers: {n} (exactly n), {n,m} (between n and m).
Common patterns: email validation ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$; Indian mobile number ^[6-9]\d{9}$. Flags: g (global -- find all matches, not just the first), i (case-insensitive), m (multiline -- ^ and $ match per line rather than per string). This tester highlights every match in real time as you type, making it fast to iterate on a pattern.
Worked Example
Pattern \b\w+@\w+\.\w+\b with the g flag against the sample text "Email me at hello@smartutilz.com or support@example.org" finds 2 matches: hello@smartutilz.com and support@example.org -- demonstrating a simplified (non-RFC-complete) email pattern useful for quick validation.
Second Worked Example: Pulling Order Codes
Paste this into the test string: Order A-102 shipped, order B-7 pending, order C-2045 done. Then try three patterns with the g flag on.
[A-Z]-\d+reports 3 matches: A-102, B-7 and C-2045. One capital letter, a hyphen, then one or more digits.\d{3,}reports 2 matches: 102 and 2045. The 7 in B-7 is skipped because it has fewer than three digits.orderreports 2 matches, but ticking i raises that to 3 because the capital O in “Order” now counts.
The tester runs the browser’s own JavaScript regular expression engine, so what you see here is what new RegExp() will do in your front-end or Node code.
Common Mistakes
- Forgetting the g flag. Without it only the first match is highlighted, even though the “Matches found” counter still counts every occurrence. If the highlight and the count disagree, check the g box.
- Leaving the dot unescaped. The pattern
3.14matches both “3.14” and “3x14” (2 matches in3.14 and 3x14), while3\.14matches only the first. - Using a greedy quantifier across tags or quotes. On
<b>one</b> and <b>two</b>,<b>.*</b>highlights the whole string as one match;<b>.*?</b>finds each tag pair separately. - Expecting ^ and $ to work per line. On three lines of text,
^\w+finds 1 match without the m flag and 3 with it. - Pasting patterns from other languages. Syntax such as
(?P<name>...)from Python is not valid in JavaScript, and the tool will show an “Invalid regex” message.
Where You Would Use This
- Building a validation rule for a signup form field before you paste it into your code.
- Extracting IDs, dates or email addresses from a pasted log or export.
- Checking a search-and-replace pattern in an editor so it does not touch lines it should not.
- Learning how anchors, character classes and lazy quantifiers behave by watching the highlight change as you type.
Tips for Building Patterns
Build a pattern in small steps. Start with a literal piece of the text you want, confirm it highlights, and then replace parts with classes such as \d or \w and add quantifiers one at a time. Keep a few lines of text that should not match in the test string, because a pattern that matches too much is as wrong as one that matches too little. When the pattern is finished, copy it into your code and escape backslashes as that language requires.