Regex Tester
Test and debug regular expressions in real time. See matches highlighted instantly.
Highlighted Matches (2)
Match Details
| # | Match | Index |
|---|---|---|
| 1 | hello@iforgeapps.com | 14 |
| 2 | support@example.co.uk | 38 |
Regular Expressions: The Developer's Swiss Army Knife
Regular expressions (regex) are patterns that match text. They're the most powerful text-search tool in programming — and also the most feared. The syntax looks like line noise at first, but once you learn the building blocks, you can validate emails, extract data, find-and-replace across files, and parse logs in seconds.
This tester uses JavaScript's built-in RegExp engine, which supports lookahead, lookbehind, named groups, and Unicode properties. Type your pattern, paste your test string, and see matches highlighted in real time — no server required.
The famous joke about regex: "Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems." It's funny because it's sometimes true — but for text matching, nothing else comes close.
Essential Regex Syntax
| Pattern | Meaning | Example Match |
|---|---|---|
| . | Any character (except newline) | a.c matches "abc", "a1c" |
| \d | Any digit (0-9) | \d3 matches "123" |
| \w | Word character (letter, digit, _) | \w+ matches "hello_123" |
| \s | Whitespace (space, tab, newline) | \s+ matches " " |
| ^ | Start of string/line | ^Hello matches "Hello world" |
| $ | End of string/line | world$ matches "hello world" |
| * | Zero or more of previous | ab*c matches "ac", "abc", "abbc" |
| + | One or more of previous | ab+c matches "abc", "abbc" (not "ac") |
| ? | Zero or one of previous | colou?r matches "color", "colour" |
| {n,m} | Between n and m repetitions | \d{2,4} matches "12", "123", "1234" |
| [abc] | Character class (any of a, b, c) | [aeiou] matches any vowel |
| (group) | Capture group | (\d+)-(\d+) captures "12" and "34" |
Common Ready-to-Use Patterns
| What to Match | Pattern | Notes |
|---|---|---|
| Email address | [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} | Covers 99% of real emails |
| UK phone number | (?:\+44|0)\d{10} | Matches 07xxx and +447xxx |
| UK postcode | [A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2} | Case-insensitive with i flag |
| URL | https?://[\w.-]+(?:\.[\w]+)+[\w._~:/?#@!amp;'()*+,;=-]* | HTTP and HTTPS |
| Date (YYYY-MM-DD) | \d{4}-\d{2}-\d{2} | Doesn't validate actual dates |
| Hex colour | #[0-9a-fA-F]{3,6} | Matches #fff and #ffffff |
| IP address (v4) | \b(?:\d{1,3}\.){3}\d{1,3}\b | Doesn't validate range (0-255) |
Regex Flags Explained
g — Global
Find all matches, not just the first one. Essential for search-and-replace operations across entire strings.
i — Case-insensitive
Matches regardless of upper/lowercase. "hello" matches "Hello", "HELLO", "hElLo".
m — Multiline
Makes ^ and $ match start/end of each line, not just the entire string. Essential for line-by-line processing.
s — DotAll
Makes . match newline characters too. Without this, . matches everything except \n.
u — Unicode
Enables full Unicode matching. Required for correctly handling emojis, CJK characters, and \p Unicode properties.
d — HasIndices
Returns start/end indices for each capture group. Useful when you need to know the exact position of matches.
Copy-Paste Regex Patterns
| What to Match | Pattern | Example Match |
|---|---|---|
| UK postcode | ^[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}$ | SW1A 1AA |
| UK mobile number | ^07\d{9}$ | 07911123456 |
| Email (basic) | ^[^\s@]+@[^\s@]+\.[^\s@]+$ | user@example.com |
| IPv4 address | \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b | 192.168.1.1 |
| Date (DD/MM/YYYY) | \d{2}/\d{2}/\d{4} | 15/04/2026 |
| Hex colour | #[0-9A-Fa-f]{6}\b | #FF5733 |
These patterns work in most regex engines (JavaScript, Python, PHP). For production email validation, don't rely on regex alone — send a confirmation email. Regex can check format, but only delivery confirms the address exists.
Related Tools
How to use this tool
Enter a regex pattern
Add flags (g, i, m, etc.)
Paste your test string
Common uses
- Validating email addresses and phone numbers
- Extracting data from log files and text
- Find-and-replace with pattern matching
- Parsing URLs and query parameters
- Testing patterns before using them in code
Share this tool