Regex Tester

Test a regular expression against a string and see every match, with capture groups.

How to Use the Regex Tester

  1. Enter your regex pattern (without the surrounding slashes) into "Regex Pattern".
  2. Set "Flags" (e.g. g for all matches, gi for global case-insensitive).
  3. Paste your "Test String" and click "Test" to see every match with its position and capture groups.

What Happens When You Click Test

The pattern and flags you type are passed straight to the browser's built-in RegExp constructor. If the browser rejects the pattern, for example because a bracket is not closed, its own error message is shown above the results so you can see exactly what it objected to.

With the g flag, the tool collects every match in the test string. Without it, only the first match is reported. Each row of the result table shows the matched text, the index where it starts, and the value of each capture group in order. The index counts characters from zero, so a match at the very start of the text has index 0.

Because the pattern is typed into a text box rather than written inside JavaScript source code, you type each backslash once. Write \d, not the doubled form you would need inside a quoted string in code.

Worked Example: Pulling Dates Out of Text

Say you want to find dates written as DD/MM/YYYY, the format most Indian documents use, and separate the day, month and year. Enter this pattern with the flag g:

(\d{2})/(\d{2})/(\d{4})

Test string: Invoice dated 15/08/2026, paid on 02/10/2026.

#MatchIndexGroups
115/08/20261415, 08, 2026
202/10/20263402, 10, 2026

Remove the g flag and only the first row appears. Note that this pattern checks the shape of the text, not whether the date is real: 31/02/2026 would also match. Checking calendar validity is a job for code, not for a regular expression.

Quick Reference: Common Tokens

TokenMeaning
\d / \DA digit 0 to 9 / any character that is not a digit
\wA basic Latin letter A to Z or a to z, a digit or an underscore. It does not match Hindi or other non-Latin letters.
\sA space, tab or line break
.Any character except a line break (including line breaks with the s flag). To match a real full stop, write a backslash before it.
^$Start and end of the text, or of each line with the m flag
\bA word boundary, useful to avoid matching inside a longer word or number
[abc][^abc]Any one of the listed characters / any character not listed
*+?Zero or more, one or more, zero or one of the previous item. Add ? after them to make them match as little as possible.
{n}{n,m}Exactly n times, or between n and m times, written with curly braces
( )(?: )A capture group, shown in the Groups column / a group that does not capture
a|bEither the left side or the right side

Format Patterns for Common Indian IDs

These patterns check that a value has the right shape. Paste one into the pattern box, leave the flags empty, and test a single value. They do not prove that a number was actually issued; the GSTIN pattern, for example, does not verify the final check character.

ValuePatternRule it checks
Mobile number^[6-9]\d{9}$10 digits starting with 6, 7, 8 or 9, without the +91 prefix
PIN code^[1-9]\d{5}$6 digits, first digit not zero
PAN^[A-Z]{5}\d{4}[A-Z]$5 capital letters, 4 digits, 1 capital letter, such as ABCDE1234F
IFSC^[A-Z]{4}0[A-Z0-9]{6}$4-letter bank code, a zero, then a 6-character branch code
GSTIN^\d{2}[A-Z]{5}\d{4}[A-Z][1-9A-Z]Z[0-9A-Z]$15 characters: state code, the holder's PAN, an entity number, the letter Z and a check character

Common Mistakes

  • Leaving out ^ and $ when validating a whole value. Without them, the PAN pattern above would also match inside a longer string such as XABCDE1234FY.
  • Typing the flags with commas or spaces. The flags box expects letters run together, such as gi. Anything else is rejected as an invalid flag.
  • Using a greedy .* between two markers. In the text "a" and "b", the pattern ".*" matches from the first quote to the last one in a single match. Use .*? or a negated class such as [^"]* instead.
  • Forgetting to escape special characters. A full stop, plus sign, bracket or question mark has a special meaning, so put a backslash before it to match it literally, for example \. in a domain name.

Frequently Asked Questions

It uses JavaScript's native regular expression engine (the same one used by browsers), so syntax follows standard JavaScript regex rules.

Common flags are g (global — find all matches, not just the first), i (case-insensitive), m (multiline, so ^ and $ match line boundaries), and s (dot matches newlines).

Without the global (g) flag, JavaScript's regex engine only reports the first match in the string — add 'g' to the flags field to see every match.

Basic syntax such as character classes, quantifiers, groups and anchors behaves the same in most languages. Details differ: named groups, lookbehind, Unicode handling and flag letters vary between engines, and some features exist in one language but not another. Test the final pattern in the language you will deploy it in.

A group that is optional, or sits in a branch of an alternation that was not used, does not take part in the match. JavaScript then reports it as undefined, which appears as an empty entry in the Groups column, or as a dash when no group has a value.
No ratings yet — be the first!
Rate this calculator:

Related Calculators

Was this tool helpful?