Regex Tester
Test JavaScript regex live: highlight matches, see groups, preview replace
| Pattern | Meaning |
|---|---|
| . | Any character except a line break (any at all with s) |
| \d \w \s | Digit, word character [A-Za-z0-9_], whitespace |
| \D \W \S | NOT 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 \B | Word 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|b | a 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 with | Inserts |
| $1 โฆ $99 | Numbered 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
- 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.
- Tap the flags you need:
gto find every match,ito ignore case,mfor line-by-line^and$, and so on. If the pattern has a mistake, a red message explains it. - Paste your sample into Test text. The match count and the highlighted text update as you type.
- 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. - 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/flagsliteral.
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.
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
| Flag | Name | What it does |
|---|---|---|
g | global | Find all matches, not just the first |
i | ignore case | pan also matches PAN |
m | multiline | ^ and $ match at the start and end of every line |
s | dotAll | . also matches line breaks |
u | unicode | Treats emoji as one character and enables \p{โฆ}, e.g. \p{Script=Devanagari} for Hindi text |
y | sticky | Each match must start exactly where the previous one ended |
d | indices | Also 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.
| Value | Pattern | Rule |
|---|---|---|
| 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,$2numbering 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.