Regex Tester
Test and debug regular expressions in real time. See matches highlighted instantly.
Enter a regular expression and test string to see matches, capture groups, and replacements in real time. Uses JavaScript regular expressions and common flags (g, i, m, s, u, d).
Use it to check JavaScript regex behaviour before adding a pattern to app code, logs, or validation rules.
Highlighted Matches (2)
Match Details
| # | Match | Index |
|---|---|---|
| 1 | https://iforgeapps.com/tools/ | 6 |
| 2 | https://example.com/docs | 39 |
Regular Expressions for Text Matching
Regular expressions (regex) are patterns that match text. The syntax can look like line noise at first, but once you learn the building blocks, you can validate simple formats, extract data, search and replace across files, and parse logs.
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.
Regex is best for matching regular text patterns. It is not a substitute for a full parser when the input has nested structure, business rules, or security consequences.
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 [at] example dot 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.
Capture Groups and Replacement
Parentheses do two things: they group part of a pattern, and they capture the matched text for later use. In JavaScript replacement strings, $1 refers to the first capture, $2 to the second, and so on.
| Goal | Pattern | Replacement | Result |
|---|---|---|---|
| Swap date order | (\\d{4})-(\\d{2})-(\\d{2}) | $3/$2/$1 | 2026-04-15 becomes 15/04/2026 |
| Extract domain | https?://([^/]+) | $1 | https://example.com/docs gives example.com |
| Wrap words | \\b(urgent)\\b | <strong>$1</strong> | Marks matching words for HTML output |
Named groups use syntax such as (?<year>\d{4}). They make larger patterns easier to read, especially when several groups have similar shapes.
Escaping Rules That Cause Bugs
Pattern input
To match a literal dot, type \.. A bare dot means any character.
JavaScript strings
In source code strings, backslashes need another layer of escaping. The pattern \d+ is written as "\\d+".
Character classes
Some characters lose special meaning inside brackets. A dot in [.] is literal, but a caret at the start negates the class.
URLs and slashes
If you use regex literal syntax in code, forward slashes must be escaped. In this tester, type the pattern only, without surrounding slashes.
Performance and Backtracking
Most regex patterns are fast on normal text. Slowdowns usually come from nested quantifiers, ambiguous alternatives, and patterns that try many paths before failing.
| Risky Pattern | Why It Hurts | Safer Direction |
|---|---|---|
| (a+)+$ | Nested quantifiers can retry exponentially | Use one clear repetition where possible |
| (.*)(.*) | Two greedy groups fight over the same text | Make boundaries explicit |
| (cat|caterpillar) | Short alternative can win before longer one | Order longer alternatives first when needed |
| .*error | Greedy scan across a huge string | Limit the character class or line scope |
When Regex Is the Wrong Tool
HTML and XML parsing
Use a DOM parser for nested tags, attributes, comments, and malformed markup. Regex can help find simple snippets, but it is brittle for full documents.
JSON and code
Use JSON.parse, an AST parser, or a language-aware tool. Strings, escapes, and nested blocks quickly outgrow regular matching.
Security decisions
Regex can check a rough format, but it should not be the only control for authentication, authorisation, or abuse prevention.
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
Frequently Asked Questions
What regex engine does this tool use?
Is my data sent to a server?
What regex flags are available?
Why does my regex match nothing?
What's the difference between .* and .*? (greedy vs lazy)?
How do I match a literal dot or bracket?
What's a capture group and how do I use it?
Can I use lookahead and lookbehind?
How do I write a regex for email validation?
Why is my regex slow on long strings?
What's the difference between ^ and \\A (start anchors)?
Can regex match across multiple lines?
Results are for general informational purposes only and should be checked before use. They are not professional advice. See our Disclaimer and Terms of Service.