Quick Answer
Type your regular expression between the slashes, tick the flags you need (g for all matches, i to ignore case, m for multiline), and paste some test text. Every match is highlighted as you type, and a table lists each match with its position and capture groups — including named groups like (?<user>…). Add a replacement such as $<user> at $<domain> to preview the result. Runaway patterns are stopped safely after 2 seconds.
What is a Regex Tester?
A Regex Tester (रेगेक्स टेस्टर) is a playground for regular expressions — compact patterns that describe text. With a regex you can check whether an email address or PAN number looks valid, pull every phone number out of a document, find dates, split log lines into fields, or rewrite text in bulk. Regular expressions are built into almost every programming language, text editor and database, but their syntax is dense, and a single misplaced character can change what they match. Testing patterns interactively is the quickest way to get them right.
This free tester uses the same JavaScript regex engine that runs in your browser and in Node.js. Type a pattern, choose flags and paste sample text: every match is highlighted instantly, a table shows each match's position and capture groups (including named groups), and an optional replacement field previews the output of a search-and-replace. Patterns run inside a background Web Worker with a two-second limit, so even a pattern with catastrophic backtracking cannot freeze the page.
Key Features
- Live highlighting — alternating colours make adjacent matches easy to see.
- Match table — number, index, full match and every capture group.
- Named groups — group names shown in the table header.
- All six flags — g, i, m, s, u and y.
- Replace preview — $1, $<name>, $& and other replacement tokens.
- Copy as a /pattern/flags literal or a new RegExp statement.
- Built-in cheat sheet of the most useful tokens.
- Safe execution — 2-second time limit in a worker.
How to Test a Regex — Step by Step
- Type the pattern between the slashes (don't type the slashes).
- Tick the flags — the current flags appear after the closing slash.
- Paste test text that includes both strings that should match and strings that shouldn't.
- Read the highlights and the match table; adjust the pattern until only the right parts match.
- Optionally enter a replacement to preview the transformed text.
- Copy the regex into your code.
Worked Example: Extracting Emails
The sample pattern (?<user>[\w.+-]+)@(?<domain>[\w-]+\.[\w.]+) with the g flag finds two matches in the sample text: info@promptminds.in and sales.team@example.co.uk. The table shows the user and domain groups separately, while the invalid strings “user@” and “@domain.com” are not matched. Enter the replacement $<user> at $<domain> to see “info at promptminds.in”. Real-world email validation is more complex than any short regex, so use patterns like this for extraction and simple checks, and confirm addresses by sending a verification email.
Flags Explained
| Flag | Name | Effect |
|---|---|---|
| g | global | Find all matches, not just the first |
| i | ignore case | A matches a, Z matches z |
| m | multiline | ^ and $ match at the start and end of every line |
| s | dotAll | . also matches line breaks |
| u | unicode | Full Unicode: \p{…} escapes, emoji as single characters, stricter syntax |
| y | sticky | Match only at the exact current position (lastIndex) |
Useful Patterns to Start From
| Purpose | Pattern |
|---|---|
| Indian mobile number | (?:\+91[\s-]?)?[6-9]\d{9} |
| PIN code (India) | \b[1-9]\d{5}\b |
| PAN format | \b[A-Z]{5}\d{4}[A-Z]\b |
| Date YYYY-MM-DD | \b(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\b |
| Hex colour | #(?:[0-9a-fA-F]{3}){1,2}\b |
| URL (simple) | https?:\/\/[^\s/$.?#].[^\s]* |
| Devanagari words | \p{Script=Devanagari}+ (with u flag) |
| Extra spaces | [ \t]{2,} |
These patterns check format, not truth — a PAN-shaped string is not necessarily a real PAN. Always validate important data on the server as well.
Groups, Back-References and Lookarounds
Capturing groups ( … ) remember what they matched, available as $1, $2 in replacements and in the match table. Non-capturing groups (?: … ) group without remembering, which keeps numbering simple. Named groups (?<name> … ) can be referred to as $<name>. A back-reference such as \1 matches the same text again — (\w)\1 finds doubled letters. Lookaheads (?= … ) and (?! … ) and lookbehinds (?<= … ) and (?<! … ) check what comes before or after without including it in the match — for example \d+(?=%) finds numbers followed by a percent sign.
Catastrophic Backtracking
Regex engines like JavaScript's work by backtracking: when a path fails, they go back and try another way to split the text. Patterns with nested or overlapping quantifiers — (a+)+, (.*)*, (\w+\s?)+ — can force the engine to try an exponential number of combinations on certain inputs, taking seconds, minutes or longer. In production this is a denial-of-service risk known as ReDoS. This tester protects you by running each pattern in a separate worker thread and stopping it after two seconds. If you see the timeout message, simplify the pattern: make alternatives mutually exclusive, avoid quantifiers inside quantifiers, and anchor patterns where possible.
A Step-by-Step Way to Build a Pattern
- Collect examples — paste several strings that should match and several that should not.
- Start specific — match one real example literally, then generalise piece by piece (replace digits with \d, letters with a class).
- Anchor it — add ^ and $ (with m for line-by-line data) or word boundaries so partial matches don't slip through.
- Add groups for the parts you want to extract, and name them.
- Test edge cases — empty strings, extra spaces, very long input, unusual characters, Hindi text.
- Simplify — remove anything that doesn't change the result; simpler patterns are faster and easier to maintain.
Keep the test text with your code as a comment or unit test, so the next person can see exactly what the pattern is meant to accept and reject.
Performance Tips
Most regexes run in microseconds, but patterns applied to large files or used on every request deserve care. Prefer specific character classes ([^,]* instead of .*), anchor patterns at the start, avoid alternations with shared prefixes (cat|category → cat(?:egory)?), and compile a regex once rather than inside a loop. If a pattern feels slow in this tester on realistic text, it will be slow in production too.
Using Your Regex in Code
- JavaScript:
const re = /pattern/g; text.match(re); text.replace(re, '$1'), orfor (const m of text.matchAll(re))to loop with groups. - Python:
re.findall(r'pattern', text)— note Python names groups with (?P<name>…). - Java: double every backslash inside string literals: "\\d+".
- Databases: PostgreSQL ~ and MySQL REGEXP support most basic syntax but differ in advanced features.
Common Uses
- Form validation for phone numbers, PIN codes and IDs.
- Extracting data from logs, CSVs and scraped text.
- Bulk search-and-replace in editors and scripts.
- URL routing and rewrite rules.
- Cleaning and normalising user input.
- Learning regular expressions step by step.
- Writing filters for analytics tools, which often accept regular expressions for page paths.
- Testing patterns before adding them to a .htaccess, Nginx or firewall rule.
Common Mistakes to Avoid
- Forgetting the g flag and wondering why only one match appears.
- Unescaped dots — . matches any character; use \. for a full stop.
- Greedy .* swallowing too much — use .*? or a negated class like [^"]*.
- Using \w for non-English text — use \p{L} with the u flag.
- Trying to parse HTML or JSON with regex — use a real parser.
Troubleshooting
- “Invalid regular expression” — the message names the problem, such as an unterminated group or an invalid escape in u mode.
- Zero-length matches shown as ∅ — patterns like ^ or \b match positions, not characters.
- Named groups missing from the header — names are shown when every group is named.
Quick Glossary
- Pattern: the regular expression itself.
- Quantifier: *, +, ?, {n,m} — how many times to repeat.
- Character class: [abc] or \d — a set of allowed characters.
- Anchor: ^, $ or \b — a position rather than a character.
- Capture group: a bracketed part whose match is remembered.
- ReDoS: regular-expression denial of service caused by catastrophic backtracking.
- Lookaround: a lookahead or lookbehind that checks context without consuming characters.
- Back-reference: \1 or \k<name>, matching the same text a group matched earlier.
- Greedy / lazy: matching as much / as little as possible.
Why Use This Regex Tester?
It uses the real JavaScript engine, shows matches and groups clearly, previews replacements, ships with a cheat sheet and practical patterns, and protects your browser from runaway expressions — free and private.
Regex Tester — Key Facts
| Flavour | JavaScript (ECMAScript) — the same engine as browsers and Node.js |
|---|---|
| Flags | g global · i ignore case · m multiline · s dotAll · u unicode · y sticky |
| Results | Highlighted matches, index, numbered and named groups |
| Replace | Preview with $1, $<name>, $& |
| Safety | Runs in a Web Worker, stopped after 2 seconds |
| Extras | Copy as /pattern/flags or new RegExp(…), cheat sheet |
Frequently Asked Questions
What is a regex tester?
A regex tester lets you write a regular expression and immediately see what it matches in sample text. It is the fastest way to build, understand and debug patterns before putting them into code.
Which regex flavour does this tool use?
JavaScript (ECMAScript), executed by your browser's own regex engine — exactly what runs in web pages and Node.js. Most syntax is shared with Python, Java and PCRE, but features like possessive quantifiers or inline flags (?i) differ.
What do the flags mean?
g finds all matches instead of the first; i ignores case; m makes ^ and $ match at line breaks; s lets . match new lines; u enables full Unicode mode (needed for \p{L} and emoji); y (sticky) matches only at the current position.
How do I use named groups?
Write (?<name>pattern). The match table shows the group's name, and in the replacement you can refer to it as $<name>. Named groups make long patterns easier to read.
Why does my pattern only find one match?
Without the g flag, a regex stops after the first match. Tick g to find all matches.
Why did the tester stop with a timeout?
Some patterns, such as (a+)+$ on a long string of a's, take exponential time — catastrophic backtracking. The tester runs patterns in a background worker and stops them after 2 seconds so your browser stays responsive. Rewrite the pattern to avoid nested quantifiers.
How do I match Hindi or other non-English letters?
Turn on the u flag and use Unicode property escapes: \p{L} matches any letter, \p{Script=Devanagari} matches Devanagari characters. \w only matches English letters, digits and underscore.
How do I match a literal dot or bracket?
Escape it with a backslash: \. matches a full stop, \( and \) match brackets, \\ matches a backslash.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +) match as much as possible; lazy ones (*?, +?) match as little as possible. For example <.+> on “<b>x</b>” matches the whole string, while <.+?> matches just “<b>”.
Can I copy the regex into my code?
Yes. “Copy regex” gives /pattern/flags for JavaScript literals, and “Copy as JavaScript” gives a new RegExp(…) statement with the pattern correctly escaped as a string.
Is my text uploaded?
No. Everything runs in your browser, including the background worker.
Is the Regex Tester free?
Yes. It is free, unlimited and needs no sign-up.
Build Regex with Confidence!
Live matches, groups and replace preview — free, safe and private.
Explore More Prompt Minds Tools
Regex Tester works great alongside our other free tools. Every Prompt Minds tool runs entirely in your browser — no sign-up, no uploads, no watermarks. Browse all free tools.
