โœฆ Developer Tool ยท Interactive
โ† Back to dev

Regex Tester

Test regular expressions on your own sample text, see each match and capture group, and spot greedy or unanchored patterns before they reach your code.

{ } Developer Toolโšก Instant result
</>
{ } 01 ยท DEVELOP

Check a regular expression before it reaches production

A regex that looks right can still match too much, too little or nothing at all. Running it against real sample text is the fastest way to find out. A regex tester highlights matches as you type, lists captured groups and lets you toggle flags. You catch the awkward edge cases before your users do.

Testing a pattern in five moves

  1. Paste the text you want to search, such as a log extract or a column of phone numbers.
  2. Type the pattern without surrounding slashes, for example \d{6} for a six-digit PIN code.
  3. Set flags such as g for every match or i to ignore case.
  4. Read the match list and confirm each capture group holds what you expect.
  5. Add hostile inputs, like blank lines or stray spaces, and check the pattern still behaves.

Regex cheat sheet: tokens you will use most

TokenMeaningExample
.Any character except a line breaka.c matches abc and a-c
\dA digit from 0 to 9\d\d matches 42
\wLetter, digit or underscore\w+ matches user_1
\sWhitespaceSpace, tab or newline
^ and $Start and end of the string^Hi$ matches only Hi
*, +, ?Zero or more, one or more, optionalcolou?r matches both spellings
{2,4}Between two and four repeats\d{2,4} matches 123
[abc]Any one listed character[aeiou] matches vowels
(...) and (?:...)Capturing and non-capturing groups(\d{4}) saves a year
a|bEither sidecat|dog

Flags in one line each

  • g (global): return every match, not just the first.
  • i (ignore case): India also matches INDIA.
  • m (multiline): ^ and $ work on each line, not only the whole text.
  • s (dotAll): lets the dot match line breaks too.
  • u (unicode): treats emoji as single characters and enables escapes like \p{L}.

Ready-made patterns for Indian data formats

These are starting points, not bulletproof validators. Adjust each one to your exact business rules.

DataPatternNotes
Mobile number^[6-9]\d{9}$Ten digits starting 6-9, no +91
PIN code^[1-9]\d{5}$Six digits, first digit not zero
PAN^[A-Z]{5}\d{4}[A-Z]$Five letters, four digits, one letter
GSTIN shape^\d{2}[A-Z]{5}\d{4}[A-Z][1-9A-Z]Z[0-9A-Z]$Does not verify the check character
Date (DD/MM/YYYY)^\d{2}/\d{2}/\d{4}$Accepts 31/02/2025, so validate dates in code
Email (simple)^[^\s@]+@[^\s@]+\.[^\s@]+$Catches typos, not every valid address

Email is the classic trap. The full address grammar is far too complex for a practical pattern. A simple shape check plus a confirmation email works better in real forms.

Why your regex is not matching (or matches too much)

  • Unescaped special characters: the dot in example.com matches any character. Write example\.com instead.
  • Greedy quantifiers: <.+> runs from the first < to the very last >. The lazy form <.+?> stops early.
  • Missing anchors: without ^ and $, a pattern matches inside longer strings. An 11-digit number still contains a valid-looking mobile number.
  • Double escaping: in a Java string or a new RegExp() string, \d must be written as \\d.
  • Flavour differences: lookbehind, named groups and possessive quantifiers vary across JavaScript, Python, PCRE and Java.

Catastrophic backtracking

Nested quantifiers such as (a+)+$ can force the engine through millions of paths on a failing input. The browser tab freezes or the server stalls. This weakness is known as ReDoS, a form of denial of service. If a test hangs on a short string, flatten the nesting or use atomic groups where your flavour supports them.

Browser-based testers, the ToolsMate regex tester included, normally rely on the JavaScript engine. Recheck any pattern in your target language before shipping it.

</> 02 ยท UNDERSTAND

How this developer tool works

01

Enter the required information

Use the fields in the tool above and keep units and formats consistent.

02

Run the tool

Review the result shown in the output area.

03

Check the assumptions

Confirm that the result matches your situation before using it for a decision.

</> 03 ยท FORMULA / LOGIC

Which formula or logic is used?

</>The first line is treated as the regular expression and remaining lines as test text.

This describes the core logic used by the tool. Check any assumptions that may affect your result.

โœฆ 04 ยท IMPORTANT

Things to know before using Regex Tester

01

Use accurate inputs and keep units consistent.

02

Review the assumptions before using the result for a decision.

03

Compare important results with an independent or official source.

? 05 ยท FAQ

Frequently Asked Questions

Which regex flavour does an online regex tester use?+

Most browser-based testers run JavaScript's built-in RegExp engine. That closely matches Node.js behaviour but differs from Python, PHP and Java in places. Lookbehind support, named group syntax and Unicode handling are the usual areas to recheck.

How do I match a literal dot or bracket in regex?+

Put a backslash in front of it. Write \. for a dot, \( for a round bracket and \[ for a square one. Inside a character class such as [.], most special characters lose their meaning, so the dot needs no escape there.

What is the difference between greedy and lazy matching?+

Greedy quantifiers like .* grab as much text as possible, then give some back if needed. Lazy versions like .*? take as little as possible. For pulling text from between quotes or tags, the lazy form usually gives the result you want.

How do I validate a 10-digit Indian mobile number with regex?+

Use ^[6-9]\d{9}$, which requires ten digits beginning with 6, 7, 8 or 9. To allow an optional +91 or 0 prefix, try ^(?:\+91|0)?[6-9]\d{9}$ instead. Strip spaces and hyphens from user input before testing it.

Why does my regex work in the tester but not in my code?+

Escaping usually changes when the pattern moves into a quoted string. Many languages need every backslash doubled there. Also confirm the same flags carried over. Then check your language supports each feature, such as lookbehind or named groups.

What are capture groups used for?+

Capture groups, written with round brackets, save part of a match for later. You might extract the year from a date, or reuse a group in a replacement as $1 or \1. Use (?:...) when you need grouping without saving anything.

Can regex parse HTML reliably?+

Not reliably. HTML allows nesting, optional closing tags and attributes in any order, which regular expressions cannot fully model. Regex is fine for quick extraction from predictable markup. For anything dependable, use a real parser such as DOMParser or BeautifulSoup.

โ—Ž 08 ยท CATEGORY HUBS

Explore TheToolsMate