About Regex Tester
Regex Tester lets you test and check a regular expression against sample text using the same RegExp engine that runs your JavaScript and TypeScript code, so a pattern that works here works in Node.js, Deno, Bun, and every modern browser. Matches are highlighted in place, numbered and named capture groups are listed, and a replace field previews substitution tokens such as $1 and $&. The pattern and text never leave your browser.
How to use Regex Tester
- Enter a pattern and the flags you need (g, i, m, s, u, y, d).
- Paste the text you want to test.
- Review highlighted matches and capture groups.
- Optionally enter a replacement string to preview substitutions.
Examples
Words
The pattern \w+ with the global flag finds every word in a sentence.
Named groups
(?<year>\d{4})-(?<month>\d{2}) captures 2026-10 as year = 2026 and month = 10.
Reformat dates with replace
Pattern (\d{2})/(\d{2})/(\d{4}) with replacement $3-$2-$1 turns 24/11/2026 into 2026-11-24.
JavaScript regex flags
Flags change how the whole pattern behaves. Pick them next to the pattern instead of typing /pattern/flags.
| Flag | Name | What it does |
|---|---|---|
| g | global | Finds every match instead of stopping at the first. Needed for matchAll and replaceAll. |
| i | ignoreCase | Matches letters regardless of case, so /abc/i matches ABC. |
| m | multiline | Makes ^ and $ match at the start and end of every line, not only the whole text. |
| s | dotAll | Lets . match line breaks as well. |
| u | unicode | Treats the pattern as Unicode code points and enables \p{…} property escapes such as \p{L}. |
| v | unicodeSets | A stricter Unicode mode with set operations in character classes (newer browsers only). |
| y | sticky | Matches only at the exact position in lastIndex, for step-by-step tokenizers. |
| d | hasIndices | Records the start and end index of each capture group in match.indices. |
Regex cheat sheet
| Syntax | Meaning | Example |
|---|---|---|
| . | Any character except a line break (any at all with the s flag) | a.c matches abc and a-c |
| \d \w \s | A digit, a word character (letter, digit, _), whitespace | \d{3} matches 123 |
| \D \W \S | The opposite of \d, \w, \s | \S+ matches a run of non-spaces |
| [abc] [^abc] [a-z] | One character from a set, not in a set, or in a range | [aeiou] matches a vowel |
| * + ? | 0 or more, 1 or more, 0 or 1 of the previous item | colou?r matches color and colour |
| {n} {n,} {n,m} | Exactly n, at least n, between n and m times | \d{2,4} |
| *? +? ?? | Lazy versions: match as little as possible | <.+?> matches one HTML tag |
| ^ $ | Start and end of the text (or line with m) | ^\d+$ allows digits only |
| \b | A word boundary | \bcat\b skips concatenate |
| (…) (?:…) | Capturing group, non-capturing group | (ab)+ captures ab |
| (?<name>…) | Named capturing group, read as match.groups.name | (?<year>\d{4}) |
| a|b | Either a or b | jpe?g|png |
| (?=…) (?!…) | Lookahead: followed by, not followed by | \d+(?= KB) matches 50 in 50 KB |
| (?<=…) (?<!…) | Lookbehind: preceded by, not preceded by | (?<=₹)\d+ matches 500 in ₹500 |
| \1 \k<name> | Backreference to an earlier group | (\w)\1 matches ll in hello |
Common patterns to copy
Paste any of these into the tester to try them. They are practical checks for form input, not full validators: an email that matches can still bounce, and a PAN that matches may not exist.
| Pattern | Checks |
|---|---|
| ^[^\s@]+@[^\s@]+\.[^\s@]+$ | An email address with one @ and a dot in the domain |
| ^https?:\/\/[^\s/$.?#][^\s]*$ | A web address starting with http:// or https:// |
| ^(?:\+91[\s-]?)?[6-9]\d{9}$ | An Indian mobile number, with or without +91 |
| ^[A-Z]{5}\d{4}[A-Z]$ | PAN card format, such as ABCDE1234F |
| ^[A-Z]{4}0[A-Z0-9]{6}$ | Bank IFSC code, such as SBIN0001234 |
| ^[1-9]\d{5}$ | Indian PIN code (6 digits, not starting with 0) |
| ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ | A date written as YYYY-MM-DD |
| ^#(?:[0-9a-fA-F]{3}){1,2}$ | A hex colour such as #fff or #1a2b3c |
| ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$ | A password with 8+ characters, a lowercase and uppercase letter, and a digit |
Using your regex in JavaScript and TypeScript
- Check a whole string: /^\d{6}$/.test(pin) returns true or false.
- Get every match with groups: for (const m of text.matchAll(/(?<key>\w+)=(?<value>\w+)/g)) { m.groups?.key }
- Replace with groups: date.replace(/(\d{2})\/(\d{2})\/(\d{4})/, "$3-$2-$1").
- Build a pattern from a string with new RegExp("\\d+", "g"). Inside a string literal every backslash must be doubled.
- In TypeScript, match() returns RegExpMatchArray | null and groups is typed as Record<string, string> | undefined, so check for null before reading groups.
- A regex with the g flag remembers lastIndex between test() calls. Create a new one or reset lastIndex when testing several strings.
Limitations
- The engine is JavaScript’s RegExp, not PCRE or Python. Lookbehind and Unicode property escapes need a modern browser.
- Patterns that backtrack heavily are stopped after two seconds so the page stays usable.
- Replacement uses JavaScript substitution tokens ($1, $&, $`, $', $<name>).
Privacy
This tool processes everything locally in your browser tab. Your input is not uploaded to Utilhex or any third party, and it is discarded when you close or reload the page. Read the privacy policy for details.
Frequently asked questions
Is my input sent anywhere?
No. Processing happens in your browser. Utilhex does not send tool input to its servers, analytics, or any AI service.
Do I need slashes around the pattern?
No. Enter the pattern only. Flags are chosen separately, so /foo/gi is the pattern foo with the g and i flags.
Why did testing stop?
A pattern that takes too long, or that would produce more than 2,000 matches, is stopped so the tab stays responsive. Simplify the pattern or shorten the text.
Does this work as a TypeScript regex tester?
Yes. TypeScript compiles regular expressions to plain JavaScript RegExp without changing them, so the matches you see here are exactly what your TypeScript code will get.
Why does my pattern work here but not in Python, PHP, or Java?
Each language has its own regex flavour. Most syntax is shared, but details differ: Python names groups (?P<name>…), PHP uses PCRE with possessive quantifiers, and JavaScript has no inline flags like (?i) in older engines. Test with the flavour your code uses.
How do I match a literal dot, slash, or bracket?
Put a backslash before it: \. matches a full stop, \/ a slash, and \[ a bracket. Inside a character class most symbols are literal, so [.] also matches a dot.