Regex Tester
Test and debug the regular expressions with this free online Regex Tester and enter a regex pattern that you want to test and instantaly see all the matching results.
You can use this tool fto test regualr expression for emails, phone numbers, URLs, IP addresses, hex colors, and many other text patterns.
This Regex Tester also supports common flags, including global (g), case-insensitive (i), multiline (m), and dotAll (s).
All testing is performed directly in your browser, and tool does not store the text and patterns you enter.
Regular Expression
Test String
Matches
Highlighted Text
What is Regular Expression (Regex)?
A Regular Expression (Regex) is a pattern matching language used to search, validate, extract, and manipulate text. Developers use regex in programming languages, databases, command-line tools, and web applications to identify specific text patterns.
Common use cases include validating email addresses, checking phone numbers, extracting URLs, parsing log files, and performing advanced text searches.
Regex Engines
A regex engine is the software component that interprets and executes a regular expression. Different programming languages and tools may use different regex engines, which means some advanced patterns may behave differently depending on where they are used.
For example, JavaScript uses its own regular expression engine, while PHP commonly uses PCRE (Perl Compatible Regular Expressions). Other programming languages may support additional features, syntax, or matching behavior.
Before using a complex regular expression in your application, it is important to test it with the same regex engine or programming environment where it will eventually run.
Real-World Regex Use Cases
Form Validation
Validate emails, passwords, phone numbers, postal codes, and user input.
Data Extraction
Extract URLs, dates, invoice numbers, and identifiers from text.
Log Analysis
Search server logs and application logs for specific patterns.
Data Cleaning
Remove unwanted characters and standardize text data.
Web Scraping
Locate specific content from HTML pages and documents.
Regex Examples Every Developer Should Know
| Purpose | Regex Pattern |
|---|---|
| Email Validation | ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ |
| Phone Number | ^\+?[0-9]{10,15}$ |
| URL Validation | https?:\/\/(www\.)?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} |
| ZIP Code | ^\d{5}(-\d{4})?$ |
| Hex Color | ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ |
| Username | ^[a-zA-Z0-9_]{3,20}$ |
| Strong Password | ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$ |
| Date (YYYY-MM-DD) | ^\d{4}-\d{2}-\d{2}$ |
| Time (HH:MM) | ^([01]\d|2[0-3]):[0-5]\d$ |
| IPv4 Address | ^(\d{1,3}\.){3}\d{1,3}$ |
| Only Numbers | ^\d+$ |
| Only Letters | ^[a-zA-Z]+$ |
| Alphanumeric | ^[a-zA-Z0-9]+$ |
| Indian PIN Code | ^[1-9][0-9]{5}$ |
| Indian Mobile Number | ^[6-9]\d{9}$ |
| Credit Card Number | ^\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}$ |
| HTML Tag | <[a-zA-Z][^>]*> |
| Whitespace | \s+ |
| Word | \b[a-zA-Z]+\b |
| Repeated Characters | (.)\1+ |
| Domain Name | ^[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$ |
| File Extension | \.[a-zA-Z0-9]+$ |
| Integer Number | ^-?\d+$ |
| Decimal Number | ^-?\d+(\.\d+)?$ |
Regex Flags Explained
g - Global
Finds all matches instead of stopping at the first match.
i - Case Insensitive
Ignores uppercase and lowercase differences.
m - Multiline
Allows ^ and $ to match line boundaries.
s - DotAll
Allows the dot character (.) to match newline characters.
u - Unicode
Enables full Unicode support, allowing regular expressions to correctly handle Unicode characters and code points.
y - Sticky
Matches only from the current position in the string, making matching behavior more strict than the global flag.
d - Indices
Returns the start and end positions of captured matches when using methods that provide match information.
v - Unicode Sets
Enables enhanced Unicode support and provides more powerful character set matching inside regular expressions.
Using Regex in JavaScript
const emailRegex =
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const email = "user@example.com";
console.log(emailRegex.test(email));
JavaScript provides built-in regex support through the RegExp object and pattern literals.
Common Regex Mistakes
Greedy Matching
Using .* can consume more text than expected.
Missing Escaping
Special characters such as . and ? must often be escaped.
Case Sensitivity Issues
Forgetting the i flag may cause valid matches to fail.
Performance Problems
Complex regex patterns can become slow on large inputs.
Regex Cheat Sheet
| Character | Legend | Example |
|---|---|---|
. |
Any character except newline | a.b matches "aab", "axb" |
\d |
Any digit (0-9) | \d+ matches "123" |
\w |
Word character (a-z, A-Z, 0-9, _) | \w+ matches "array_blog" |
^ / $ |
Start / End of string | ^Hello matches "Hello world" |
[abc] |
Any character in the set | [at] matches "a" or "t" |
+ / * |
1 or more / 0 or more | a+ matches "aaaa" |
\D |
Any character that is not a digit | \D+ matches "Hello" |
\W |
Any character that is not a word character | \W+ matches "@#$" |
\s |
Any whitespace character | \s+ matches spaces or tabs |
\S |
Any character that is not whitespace | \S+ matches "Hello" |
? |
0 or 1 occurrence of the previous character | colou?r matches "color" and "colour" |
{n} |
Exactly n occurrences | \d{4} matches "2026" |
{n,} |
n or more occurrences | \d{2,} matches "123" |
{n,m} |
Between n and m occurrences | \d{2,4} matches "1234" |
(abc) |
Capturing group | (ab)+ matches "abab" |
(?:abc) |
Non-capturing group | (?:ab)+ matches "abab" |
a|b |
Matches either a or b | cat|dog matches "cat" or "dog" |
[^abc] |
Any character not in the set | [^0-9] matches any non-digit |
[a-z] |
Any lowercase letter from a to z | [a-z]+ matches "hello" |
[A-Z] |
Any uppercase letter from A to Z | [A-Z]+ matches "HELLO" |
[0-9] |
Any digit from 0 to 9 | [0-9]+ matches "123" |
\b |
Word boundary | \bcat\b matches "cat" but not "catalog" |
\B |
Not a word boundary | \Bcat matches "cat" in "catalog" |
\\ |
Escapes a special character | \. matches a literal "." |
Common Patterns Explained
📧 Email Validation
^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$
This help you to check for valid email structure including @ and domain extension.
📱 Phone Number
\+?(\d{1,3})?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
You can macthes here various local and international phone number formant.
How to Use the Regex Tester
Enter a Regex Pattern
Enter the regular expression you want to test in the Pattern field. You can create your own pattern or select one of the available examples.
Select Regex Flags
Enable the flags you need to control how the regular expression matches text. For example, you can find all matches or ignore differences between uppercase and lowercase letters.
Add Your Test Text
Enter or paste the text you want to test against the regular expression.
View the Results
The Regex Tester automatically identifies matching text and displays information such as the total number of matches and the position of each match.