🔎 Regex Tester
By ToolNimba Web Dev Team · Updated 2026-06-19
A regular expression (regex) is a compact pattern that describes a set of strings, used to search, validate and extract text. Writing one correctly is fiddly, so it helps to try it against real input and watch what matches. Paste your pattern, pick the flags you need, and drop in a test string. This tester highlights every match, lists the capture groups for each one, and shows the total match count. Everything runs in your browser using the same JavaScript engine your code will use, so nothing is uploaded anywhere.
What is the Regex Tester?
A regex is built from literal characters and metacharacters. Literals like cat match themselves, while metacharacters carry special meaning: a dot matches any character, \d matches a digit, \w matches a word character, and quantifiers like +, * and {2,4} say how many times the preceding token may repeat. Parentheses create capture groups, which let you pull out the part of a match you actually care about, for example the year inside a date. This tool shows each captured group in its own column so you can confirm your groups line up the way you expect.
Flags change how the whole pattern behaves rather than what any single token matches. The g (global) flag tells the engine to keep going after the first match and find every occurrence, which is what drives the match count here. The i flag makes matching case insensitive. The m (multiline) flag makes the anchors ^ and $ match at the start and end of each line rather than only the whole string. The s (dotall) flag lets the dot also match newline characters, which it normally skips. You can combine flags freely.
The engine behind this page is the browser native RegExp object, the exact same one available in JavaScript through new RegExp(pattern, flags). That means a pattern that matches here will match identically in your front-end code or Node.js. Other languages such as Python, PCRE and Java share most of the same syntax but differ in a few corners (named group syntax, lookbehind support, some shorthand classes), so treat results here as authoritative for JavaScript and a very close guide elsewhere.
When to use it
- Validating user input such as email addresses, phone numbers, postcodes or usernames before you ship the pattern in a form.
- Extracting structured data (dates, prices, IDs, URLs) from a block of raw text using capture groups.
- Debugging a pattern that matches too much or too little by watching exactly which characters are highlighted.
- Learning regex syntax interactively, by changing one token at a time and seeing the effect on real input.
- Checking how a pattern behaves with different flags before pasting it into a find-and-replace or a log filter.
How to use the Regex Tester
- Type or paste your regular expression into the pattern box (no surrounding slashes needed).
- Tick the flags you want: g for all matches, i for case insensitive, m for multiline anchors, s for dot matches newline.
- Paste the text you want to search into the test string box.
- Read the highlighted matches, the match count, and the per-match capture group table that appears below.
- If the pattern is invalid, a red message explains what the engine could not parse so you can fix it.
Formula & method
Worked examples
You want to find every word that ends in "ing" in the sentence: "Testing, running and jumping are tiring."
- Pattern: \w+ing
- Flags: g (so every occurrence is found) and i (in case any word is capitalised)
- The engine scans left to right and matches Testing, running, jumping and tiring
- Each match is the full word because \w+ is greedy and grabs the letters before ing
Result: 4 matches: Testing, running, jumping, tiring
You want to pull the year and month out of dates like 2026-06 using a capture group.
- Pattern: (\d{4})-(\d{2})
- Flags: g to capture every date in the text
- (\d{4}) is group 1 and matches exactly four digits, the year
- (\d{2}) is group 2 and matches exactly two digits, the month
- For the input 2026-06 the table shows Group 1 = 2026 and Group 2 = 06
Result: Group 1 (year) = 2026, Group 2 (month) = 06
Common regex tokens and what they match
| Token | Matches |
|---|---|
| . | Any single character except newline (unless the s flag is set) |
| \d | Any digit, 0 to 9 |
| \w | A word character: letter, digit or underscore |
| \s | Any whitespace: space, tab or newline |
| ^ and $ | Start and end of the string (or of each line with the m flag) |
| * + ? | Repeat the previous token zero or more, one or more, or zero or one times |
| {2,4} | Repeat the previous token between 2 and 4 times |
| (abc) | A capture group; matches abc and stores it for extraction |
| a|b | Alternation: match either a or b |
| [a-z] | A character class: any single lowercase letter |
The four flags supported by this tester
| Flag | Name | Effect |
|---|---|---|
| g | Global | Find every match, not just the first; drives the match count |
| i | Ignore case | Treat upper and lower case as the same |
| m | Multiline | Make ^ and $ match at the start and end of each line |
| s | Dotall | Let the dot also match newline characters |
Common mistakes to avoid
- Forgetting the g flag and expecting all matches. Without the global flag the engine stops after the first match. If your count looks stuck at one but the text clearly has more, switch on g.
- Not escaping special characters. Characters like . + * ? ( ) [ ] { } | ^ $ and the backslash itself have special meaning. To match a literal dot you must write \. or it will match any character.
- Greedy quantifiers grabbing too much. A pattern that wraps any characters between two HTML tag brackets matches from the first opening bracket all the way to the last closing one. Add a question mark to make the quantifier lazy when you want the shortest possible match.
- Assuming the dot matches newlines. By default the dot does not match a newline, so a pattern can silently fail across lines. Turn on the s flag if you need the dot to span line breaks.
- Mixing up syntax from other languages. Lookbehind, named group syntax and some shorthand classes differ between engines. This tester uses the JavaScript engine, so a Python or PCRE pattern may need small adjustments.
Glossary
- Regular expression
- A pattern that describes a set of strings, used to search, match, validate or extract text.
- Metacharacter
- A character with special meaning in a pattern, such as the dot, asterisk or backslash, rather than a literal value.
- Capture group
- A part of a pattern wrapped in parentheses whose matched text is stored separately so you can extract it.
- Flag
- A modifier (g, i, m, s) that changes how the whole pattern is applied to the input.
- Quantifier
- A token such as +, * or {2,4} that says how many times the preceding element may repeat.
- Greedy and lazy
- Greedy quantifiers match as much as possible; adding a question mark makes them lazy and match as little as possible.
Frequently asked questions
Is my pattern or test text sent anywhere?
No. The tester runs entirely in your browser using the built-in JavaScript RegExp engine. Your pattern and test string never leave your device and nothing is uploaded or stored.
Which regex flavour does this tester use?
It uses the JavaScript (ECMAScript) regular expression engine, the same one in browsers and Node.js. Most syntax is shared with Python, PCRE and Java, but a few features differ, so treat results as exact for JavaScript and a close guide for other languages.
What do the g, i, m and s flags do?
The g flag finds every match instead of stopping at the first, i makes matching case insensitive, m makes ^ and $ match at the start and end of each line, and s lets the dot also match newline characters. You can combine them.
How do I see my capture groups?
Wrap part of your pattern in parentheses. When a match is found, the detail table below the highlights shows each group in its own column for the first matches, so you can confirm what each group captured.
Why does my pattern match more text than I expected?
Most quantifiers are greedy and grab as much as they can. Add a question mark to make them lazy, for example change .* to .*?, so the engine matches the shortest run that still satisfies the pattern.
What happens if my pattern is invalid?
The tester shows a red error message with the reason the engine could not compile the pattern, such as an unmatched bracket or an invalid quantifier, so you can correct it without guessing.