Regex Tester

Test JavaScript regex live: highlight matches, see groups, preview replace

JavaScript flavour
//g
Flags
global ยท tap a flag to toggle it
84 characters
Examples
Matches
Testingโ€ฆ
Running the pattern.
/\b[6-9]\d{9}\b/g
Cheat sheet
PatternMeaning
.Any character except a line break (any at all with s)
\d \w \sDigit, word character [A-Za-z0-9_], whitespace
\D \W \SNOT a digit / word character / whitespace
[abc] [^abc] [a-z]One of, none of, a range
^ $Start / end of text (of each line with m)
\b \BWord boundary / not a boundary
* + ?0 or more, 1 or more, optional
{3} {2,5} {2,}Exactly 3, 2 to 5, 2 or more
*? +? ??Lazy: as few as possible
(abc)Capture group, used as $1, $2 โ€ฆ
(?<name>abc)Named group, used as $<name>
(?:abc)Group without capturing
a|ba or b
(?=x) (?!x)Followed by x / not followed by x
(?<=x) (?<!x)Preceded by x / not preceded by x
\1 \k<name>Back-reference to a group
\. \* \(Escape a special character
\p{L} \p{Script=Devanagari}Unicode property (needs the u flag)
Replace withInserts
$1 โ€ฆ $99Numbered group
$<name>Named group
$&The whole match
$` $'Text before / after the match
$$A literal $

Runs entirely in your browser. Nothing you type or upload is sent to us or stored.

Results are for general guidance. Please check anything important before relying on it. Terms of use

How to Use

  1. Type your pattern in the Regular expression box (without the surrounding slashes), or tap one of the Examples such as Indian mobile, PAN or IFSC to start from a working pattern.
  2. Tap the flags you need: g to find every match, i to ignore case, m for line-by-line ^ and $, and so on. If the pattern has a mistake, a red message explains it.
  3. Paste your sample into Test text. The match count and the highlighted text update as you type.
  4. Scroll down to the Match list to see where each match starts and ends, plus the value of every numbered ($1) and named (<name>) group.
  5. To test a find-and-replace, switch on Replace and enter the replacement (for example $<year>-$<month>-$<day>). Copy the result, the matches, or the pattern as a /regex/flags literal.

What is a regular expression?

A regular expression (regex) is a small pattern that describes text. Instead of searching for one exact word, you describe its shape: "ten digits starting with 6 to 9", "five capital letters, four digits, one capital letter". Developers use regexes to validate form fields, pull values out of logs and CSV files, and do find-and-replace in editors such as VS Code.

This regex tester uses your browser's own JavaScript engine, so a pattern that works here behaves the same in JavaScript, TypeScript and Node.js code. Other languages (Python, Java, PHP, .NET) share most of the syntax, but details differ, for example Python's re module writes named groups as (?P<name>โ€ฆ).

How matching works

The engine starts at the first character and tries to fit the whole pattern. If it fails, it moves one character on and tries again. With the g (global) flag it keeps going after each match to find every one. Without it, only the first match is reported, which is what String.match() and replace() do in JavaScript.

Pattern: (?<day>\d{2})-(?<month>\d{2})-(?<year>\d{4}) flags: g
Text: Invoice dates: 15-08-2026 and 02-10-2026.
Match 1: "15-08-2026" at index 15 โ†’ day=15, month=08, year=2026
Replace: $<year>-$<month>-$<day>
Result: Invoice dates: 2026-08-15 and 2026-10-02.

Load the Date reorder example to try this: it turns Indian DD-MM-YYYY dates into the ISO YYYY-MM-DD format that databases and spreadsheets sort correctly.

The flags

FlagNameWhat it does
gglobalFind all matches, not just the first
iignore casepan also matches PAN
mmultiline^ and $ match at the start and end of every line
sdotAll. also matches line breaks
uunicodeTreats emoji as one character and enables \p{โ€ฆ}, e.g. \p{Script=Devanagari} for Hindi text
ystickyEach match must start exactly where the previous one ended
dindicesAlso reports the start and end position of each capture group

Patterns for common Indian formats

These check the shape of a value only. Add ^ at the start and $ at the end when validating a whole form field.

ValuePatternRule
Mobile number[6-9]\d{9}10 digits, starting with 6, 7, 8 or 9
PIN code[1-9][0-9]{5}6 digits, never starting with 0
PAN[A-Z]{5}[0-9]{4}[A-Z]5 letters, 4 digits, 1 letter
IFSC[A-Z]{4}0[A-Z0-9]{6}11 characters: bank code, a 0, then branch code
GSTIN[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]State code + PAN + entity number + Z + check character

A pattern can't tell whether a PAN or GSTIN actually exists, or whether a GSTIN's last check character is correct. Only the official portals can confirm that.

Catastrophic backtracking

Some patterns take exponentially longer as the text grows. The classic example is (a+)+$ tested on aaaaaaaaaaaaaaaaaaaaaaaaaaaa!: the engine tries every possible way of splitting the a's between the two + quantifiers before giving up. In a real website this can hang the page or a server. This tester runs your pattern in a background worker and stops it after 2 seconds, so you see a warning instead of a frozen tab. Avoid nested quantifiers on the same characters, and prefer specific classes like [^,]* over .*.

Tips

  • Escape special characters with a backslash when you mean them literally: \. \( \$ \?.
  • Use (?:โ€ฆ) for grouping when you don't need the value; it keeps $1, $2 numbering simple.
  • Lazy quantifiers such as .*? stop at the first possible end, which is usually what you want inside quotes or HTML tags.
  • Your patterns and test text stay in your browser. Nothing is uploaded.

Frequently Asked Questions

JavaScript (ECMAScript) regular expressions, run by your own browser. A pattern that works here works the same way in JavaScript, TypeScript and Node.js. Most syntax also carries over to Python, Java, PHP and .NET, but some details differ, such as Python's (?P...) style for named groups.

Use ^[6-9]\d{9}$ to require exactly 10 digits starting with 6, 7, 8 or 9. If users may type +91 or a leading 0, allow it with ^(?:\+91[\s-]?|0)?[6-9]\d{9}$. Tap the Indian mobile example in the tool to test it on sample text.

Switch on Replace and refer to groups with $1, $2 and so on, or to named groups with $. $& inserts the whole match and $$ inserts a dollar sign. For example, the pattern (\w+)@(\w+) with replacement $2:$1 turns me@home into home:me.

Probably because the g flag is off. Without the g (global) flag JavaScript stops after the first match, in exec(), match() and replace() alike. Tap the g flag to find every match. If you also use the y (sticky) flag, each match must start exactly where the previous one ended, so a gap in the text ends the search.

Because it ran for more than 2 seconds. That almost always means catastrophic backtracking, where nested quantifiers like (a+)+ or (.*)* make the engine try an exponential number of combinations. The tester runs patterns in a background worker and stops them, so your page stays usable. Make the pattern more specific to fix it.

No. Matching and replacing happen entirely in your browser, so you can safely test patterns on logs or data that contain personal information.