This regex tester online shows you exactly what a regular expression matches. Type a pattern, paste some test text, and every match is highlighted as you type. Each match is listed with its position and the value of every capture group.
How to test a regular expression online
- Pick an example, such as Email address, or type your own pattern between the slashes.
- Turn flags on or off. Keep g on to find every match.
- Paste or type your test text.
- Read the highlighted text and the list of matches. Group values appear as $1, $2 and so on.
- Tick Test a replacement to preview
text.replace()with your pattern.
Type the pattern without the surrounding slashes. The tester adds them for you.
Regex examples
| Pattern | Matches | Example match |
|---|---|---|
\b[6-9]\d{9}\b |
A 10-digit Indian mobile number starting with 6 to 9 | 9876543210 |
\b\d{6}\b |
A 6-digit PIN code | 500081 |
[\w.+-]+@[\w-]+(\.[\w-]+)+ |
A simple email address | ravi.teja@example.com |
\b(\d{2})-(\d{2})-(\d{4})\b |
A date in DD-MM-YYYY form, with day, month and year in groups | 15-03-2026 |
^\d+\..*$ with flag m |
Lines that start with a number and a dot | 1. Install Python |
\bjava\b with flag i |
The word Java in any case, but not JavaScript | JAVA |
For example, with the date pattern on the text "Exam on 15-03-2026", the tester shows one match at position 8 with $1 = "15", $2 = "03" and $3 = "2026".
Common mistake: A common mistake is forgetting to escape special characters. In
.com, the dot means "any character", so it also matches "xcom". Write\.comto match a real dot. The same goes for+ * ? ( ) [ ] { } ^ $ |and\.
Flags
| Flag | Name | What it does |
|---|---|---|
| g | global | Finds every match instead of stopping at the first |
| i | ignore case | java also matches Java and JAVA |
| m | multiline | ^ and $ match at the start and end of each line |
| s | dotAll | . also matches line breaks |
| u | unicode | Treats emoji and other characters outside the basic range as one character |
Regex cheat sheet
| Pattern | Meaning |
|---|---|
. |
Any character except a line break |
\d, \w, \s |
A digit, a word character (letter, digit, _), a space or tab |
\D, \W, \S |
The opposite of each of the above |
[abc], [^abc], [a-z] |
One of these, none of these, a range |
*, +, ? |
0 or more, 1 or more, 0 or 1 |
{3}, {2,5}, {2,} |
Exactly 3, 2 to 5, 2 or more |
^, $, \b |
Start, end, word boundary |
(abc), (?:abc), (?<name>abc) |
Capture group, group without capture, named group |
a|b |
a or b |
The full cheat sheet, including lookahead and lazy quantifiers, is under the tester.
Regex in Python and Java
The patterns you test here work in most languages with small changes:
- Python: use
re.findall(r"\b[6-9]\d{9}\b", text). Therbefore the string keeps backslashes as they are. Named groups are written(?P<name>...). - Java: use
Pattern.compile("\\b[6-9]\\d{9}\\b"). Every backslash must be doubled inside a Java string. - JavaScript: use
/\b[6-9]\d{9}\b/gdirectly, as in this tester.
Practise with string problems
Many string problems can be solved with or without regex. Try check whether a string contains only digits with the pattern ^\d+$, then solve it again with a loop. Remove all white spaces from a string is a one-liner with \s+ and replace.
Pro tip: Build a pattern in small steps. Start with the part you are sure about, check the highlights, then add one piece at a time. It is much easier than debugging a long pattern written in one go.
