Home › Generators › Regex Tester
Regex Tester
Test a regular expression against any text and see the matches instantly. Type your pattern, pick your flags, paste in some test text, and this tester lists every match with its position and highlights it in place — all in your browser, with nothing sent anywhere.
Highlighted text
Match list
jane@example.com— index 12bob@test.org— index 32
How it works
A regular expression — regex for short — is a small pattern that describes a shape of text. Instead of searching for one exact word, you describe what the word looks like: some letters, then an @ sign, then more letters, a dot, and a few more letters. That description is the email pattern loaded in the tester above, and it matches any email address in your test text, not just one specific address. Programmers use regex to validate forms, pull data out of logs, rename files in bulk, and search code — anywhere the text you want follows a shape rather than a fixed spelling.
Patterns are built from a small set of pieces. Ordinary characters match themselves: the letter a matches a, and @ matches @. Special characters do the interesting work. A dot matches any single character, \d matches any digit, \w matches any word character (a letter, a digit, or an underscore), and \s matches whitespace. Square brackets define a set: [0-9] matches one digit, [a-z] matches one lowercase letter, and [^0-9] matches anything that is not a digit. Anchors pin a match in place: ^ matches the start of the text (or of a line with the m flag) and $ matches the end.
Quantifiers say how many times a piece may repeat. A plus means one or more, a star means zero or more, and a question mark means zero or one — optional. Curly braces give an exact count: \d{3} means exactly three digits, and \w{2,5} means between two and five word characters. Parentheses group pieces together and remember what they matched, so (ab)+ matches ab, abab, and ababab, while a vertical bar gives alternatives: cat|dog matches either word. A backslash in front of a special character turns it back into an ordinary one, which is why the email pattern writes \. for the dot before the domain ending — an unescaped dot would match any character there, including a space.
The three flags change how the engine runs. The g flag, global, finds every match in the text instead of stopping after the first; without it, the tester would report only jane@example.com and miss bob@test.org. The i flag ignores case, so a pattern written in lowercase also matches uppercase text. The m flag, multiline, makes ^ and $ match the start and end of each line instead of only the whole text, which matters when your test text has several lines. Tick the boxes above and watch the match count change as you experiment.
One habit saves hours of frustration: quantifiers are greedy by default. A pattern like ".+" between two quote marks grabs as much as it possibly can — from the first quote all the way to the last quote in the line — because plus keeps eating characters until it is forced to stop. Adding a question mark after the quantifier, as in ".+?", makes it lazy: it stops at the first quote it can. If your pattern matches far more text than you expected, a greedy quantifier is usually the reason. The other common mistake is an unclosed bracket or parenthesis, which makes the whole pattern invalid — the tester shows the engine's exact error message so you can find it fast.
Worked example
Suppose you have the sentence "Email me at jane@example.com or bob@test.org" and you want to pull out the email addresses. Paste the pattern \b\w+@\w+\.\w+\b into the tester with the g flag on and the sentence as the test text.
Step 1: \b matches a word boundary — the engine finds the edge before the j in jane.
Step 2: \w+ matches one or more word characters — it eats jane.
Step 3: @ matches the literal @ sign.
Step 4: \w+ matches example, then \. matches the literal dot, then \w+ matches com.
Step 5: The final \b confirms the word ends there, so the first match is jane@example.com at index 12.
Step 6: With the g flag on, the engine keeps going and finds the second match, bob@test.org, at index 32.
The tester reports 2 matches and highlights both in the text. Try a second pattern on a different sentence: \d+ on "Order 42 has 7 items" finds two matches — 42 at index 6 and 7 at index 13 — because \d+ grabs each run of digits. Now try removing the g flag: the count drops to 1, because the engine stops at the first match. Small changes like that are the fastest way to learn what each piece of a pattern really does.
FAQ
What is a regular expression?
A regular expression, or regex, is a pattern that describes text to find. For example, the pattern digit-plus matches any run of numbers, and an email pattern matches text shaped like name at domain dot com. You use regex to search, validate, and extract text in code, editors, and search tools.
Why does my pattern say invalid?
The pattern has a syntax error, such as an unclosed bracket, an unclosed parenthesis, or a quantifier with nothing to repeat. This tester shows the exact error message from the JavaScript regex engine, which usually points at the problem. Common fixes are escaping special characters with a backslash or closing the bracket you opened.
What do the g, i, and m flags do?
The g flag finds all matches instead of stopping at the first one. The i flag makes matching case-insensitive, so A matches a. The m flag makes the start and end anchors match the start and end of each line instead of only the start and end of the whole text.
Does this tester send my text anywhere?
No. Everything runs in your browser using the built-in JavaScript regex engine. Your pattern and test text never leave your device, so you can safely test patterns against private or sensitive text.
Why does my pattern match more than I expected?
Quantifiers like star and plus are greedy by default: they match as much text as they can. For example, the pattern dot-star between quotes grabs from the first quote to the last quote in the line, not the nearest one. Add a question mark after the quantifier, like dot-star-question, to make it lazy so it stops at the first possible match.