Regex Tester
Write a regular expression and see every match highlighted, with capture groups listed.
Worked examples
Finding phone numbers in text
Pattern \d{3}-\d{4} against "Call 555-1234 or 555-9876 today."
2 matches #1 at 5: 555-1234 #2 at 17: 555-9876
Each match is highlighted in the text, and the position is the character index where the match starts.
Pulling out a name and domain
Pattern (\w+)@(\w+)\.com against "Mail [email protected] soon"
1 match #1 at 5: [email protected] group 1: ann group 2: shop
Brackets create capture groups, which are listed under each match so the parts can be checked separately.
About Regex Tester
A regular expression is a pattern that describes text, and it is used for searching, validating input and extracting fields from logs. Small changes, such as a missing escape or a greedy quantifier, can match far more than intended. A regex tester shows which parts of your sample text match as you type, so mistakes are visible straight away.
This tester highlights every match in your test string and lists capture groups separately, so you can confirm that each part of the pattern captures what you expect. Use it to check anchors, character classes, optional parts and repeated groups before adding a pattern to code, a validation rule or a search filter. Testing against realistic examples avoids surprises later.
How to use Regex Tester
- Type or paste your regular expression into the pattern field.
- Enter sample text in the test string area, using several lines if needed.
- Review the highlighted matches and the listed capture groups.
- Adjust the pattern and retest until each match is what you intended.
- Copy the final expression into your code, after checking the dialect it targets.
Common uses
- Validating an email address, postcode or identifier format in a form.
- Extracting timestamps or error codes from application logs.
- Writing a find-and-replace rule for a large document.
- Checking a routing pattern before adding it to a web server configuration.
Frequently asked questions
What is a capture group in a regex?
A capture group is a part of a pattern enclosed in parentheses. It records the text matched by that part, so you can reuse it in the result or in a replacement. For example, in a date pattern, one group can capture the year and another the month. Named groups, written with a label, make the captured values easier to identify in code.
Why does my regex match more text than I expect?
Greedy quantifiers such as asterisk and plus take as much text as possible, so a pattern like a quoted string can run across several quotation marks. Switching to a lazy quantifier, which adds a question mark, or using a negated character class usually fixes the problem. Test the pattern against long and unusual inputs to confirm the boundaries.
Do regular expressions work the same in every programming language?
No. Core syntax such as character classes and quantifiers is broadly shared, but features such as lookbehind, named groups and Unicode property escapes vary between languages and libraries. Check the documentation for the language you use, and test the expression against its rules before deploying it.
What does the g flag do in a regex?
The global flag tells the engine to find every match in the text rather than stopping at the first one. Without it, many engines return only the first occurrence. Other common flags include i for case-insensitive matching and m for multiline anchors. Flag support varies by dialect, so confirm which flags your target language accepts.
Can a regex tester reveal catastrophic backtracking?
A standard tester does not always report it directly, but slow or frozen matching on long input is the warning sign. Catastrophic backtracking happens when nested quantifiers force the engine to try huge numbers of paths on text that almost matches. Patterns such as a group with a plus inside another plus are common culprits. Test the expression against long, almost-matching input, and simplify the pattern if matching slows noticeably.