Regex Tester Online Free — Test Regular Expressions Live
The free Regex Tester lets you write a regular expression and test it against any string in real time. Matches are highlighted as you type, with capture groups and index positions shown below. All JavaScript regex flags are supported — no signup, no server required.
What Are Regular Expressions?
A regular expression (regex or regexp) is a pattern that describes a set of strings. It is one of the most powerful tools in any programmer's toolkit — a single well-crafted regex can replace dozens of lines of string-parsing code. Regular expressions are used for:
- Validating input (email addresses, phone numbers, postal codes)
- Searching and extracting data from text (log files, HTML, configuration files)
- Find-and-replace operations in code editors and the terminal
- Routing in web frameworks (URL pattern matching)
- Filtering and transforming data in data pipelines
Regular expressions originate from theoretical computer science — they were first described by mathematician Stephen Kleene in the 1950s as a formal notation for regular languages. Ken Thompson implemented them in the Unix text editor ed in 1968, which became the foundation for grep and all subsequent Unix text tools. Today, virtually every programming language and text editor supports regular expressions.
How to Use the Regex Tester
- Open the Regex Tester
- Enter your regular expression in the Pattern field
- Select the flags you need (g, i, m, s, u)
- Paste or type your test string in the Test String area
- Matches are highlighted live. Scroll down to see match details: index, length, and captured groups
Regex Flags Reference
| Flag | Name | Effect |
|---|---|---|
g | Global | Find all matches, not just the first |
i | Case-insensitive | Match regardless of letter case |
m | Multiline | ^ and $ match start/end of each line |
s | Dotall | . matches newline characters |
u | Unicode | Treat pattern and string as Unicode; required for emoji and non-BMP characters |
Core Regex Syntax Reference
Character classes
| Pattern | Matches | Example |
|---|---|---|
. | Any character except newline (with s flag: including newline) | a.c matches “abc”, “a2c” |
\d | Any digit (0–9) | \d+ matches “123” |
\D | Any non-digit | \D matches “a”, “!” |
\w | Word character: a–z, A–Z, 0–9, underscore | \w+ matches “hello_123” |
\W | Non-word character | Matches spaces, punctuation |
\s | Whitespace: space, tab, newline, return | \s+ matches any run of whitespace |
\S | Non-whitespace | \S+ matches any word |
[abc] | Any character in the set | [aeiou] matches any vowel |
[^abc] | Any character NOT in the set | [^aeiou] matches consonants |
[a-z] | Range of characters | [a-z0-9] matches lowercase letters and digits |
Quantifiers
| Quantifier | Meaning | Example |
|---|---|---|
* | Zero or more (greedy) | a* matches “”, “a”, “aaa” |
+ | One or more (greedy) | a+ matches “a”, “aaa” but not “” |
? | Zero or one (optional) | colou?r matches “color” and “colour” |
{n} | Exactly n times | \d{4} matches exactly 4 digits |
{n,} | At least n times | \d{3,} matches 3+ digits |
{n,m} | Between n and m times | \d{2,4} matches 2–4 digits |
*? | Zero or more (lazy) | Matches as few characters as possible |
+? | One or more (lazy) | Matches as few characters as possible |
Anchors and boundaries
| Pattern | Matches |
|---|---|
^ | Start of string (or line with m flag) |
$ | End of string (or line with m flag) |
\b | Word boundary — position between \w and \W |
\B | Non-word boundary |
Common Regex Patterns
Email address
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}A practical pattern that catches most valid email formats. Use the i flag to make it case-insensitive. A fully RFC 5322-compliant email regex is significantly more complex — this handles the common case reliably.
URL (http and https)
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\([-a-zA-Z0-9()@:%_+.~#?&/=]*)Matches http and https URLs. Use the g flag to find all URLs in a block of text.
Phone number (US format)
(\+1[\s-]?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}Matches formats like (555) 123-4567, 555-123-4567, and +1 555 123 4567.
IP address (IPv4)
\((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)\Validates each octet is in the range 0–255. The pattern ensures no false matches like 999.999.999.999.
ISO 8601 date (YYYY-MM-DD)
\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])Matches ISO 8601 date format with basic range validation on month (01-12) and day (01-31). Use the g flag to extract all dates from a document.
Hex color code
#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\Matches 3-digit and 6-digit hex color codes like #fff and #3a7bd5. Use the i flag for case-insensitivity.
Semantic version (semver)
\v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)\Matches version strings like 1.2.3 and v10.0.0. The optional leading v is common in git tags.
Capture Groups — Extracting Parts of Matches
Capture groups — defined with parentheses (…) — let you extract specific parts of a match. For example, to extract the domain from a URL:
https?:\/\/([\w.-]+)Group 1 captures the domain. The tester shows each captured group separately below the main match list, along with its index position in the original string.
Named capture groups
Named capture groups use the syntax (?<name>…):
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})Named groups are shown with their names in the match details, making them easier to identify when there are multiple groups. In JavaScript, named groups are available as match.groups.year, match.groups.month, etc.
Non-capturing groups
When you need to group expressions for quantifiers but do not need to capture the result, use a non-capturing group (?:…):
(?:https?:\/\/)?(www\.)?example\.comThe protocol group is used for ? (optional) without being captured. This avoids polluting your results with groups you don't need.
Lookahead and Lookbehind
Lookaheads and lookbehinds are zero-width assertions — they match a position based on what precedes or follows, without including those characters in the match.
| Syntax | Type | Matches |
|---|---|---|
(?=…) | Positive lookahead | Position followed by pattern |
(?!…) | Negative lookahead | Position NOT followed by pattern |
(?<=…) | Positive lookbehind | Position preceded by pattern |
(?<!…) | Negative lookbehind | Position NOT preceded by pattern |
Example — match numbers followed by “px” (pixel values) without including “px”:
\d+(?=px)Example — match prices preceded by a dollar sign, without including “$”:
(?<=\$)\d+(\.\d{2})?Greedy vs Lazy Matching
By default, quantifiers are greedy — they match as many characters as possible. Adding ? after a quantifier makes it lazy — it matches as few characters as possible.
The classic example: matching content between HTML tags.
- Greedy:
<.+>on<b>bold</b> text <i>italic</i>matches from<b>all the way to</i>— the largest possible match. - Lazy:
<.+?>matches each tag individually:<b>,</b>,<i>,</i>.
Lazy matching is almost always what you want when extracting content between delimiters.
Debugging Regex That Isn't Matching
- Check escaping: Dots, brackets, and parentheses have special meanings. To match a literal dot, use
\.not.. To match a literal bracket:\[. - Check flags: Without the
gflag, only the first match is returned. Withouti, case mismatches silently fail. - Check anchors:
^and$anchor to start/end of string by default. Add themflag to match line boundaries. - Check greedy vs lazy: If the match is too wide, add
?after the quantifier to make it lazy. - Test incrementally: Start with a simple pattern that matches something, then make it more specific one piece at a time. The tester highlights matches live, so you can see exactly where a pattern starts to fail.
- Check encoding: For non-ASCII text and emoji, add the
uflag. Without it, emoji and characters outside the Basic Multilingual Plane may not match as expected.
Test Regular Expressions Free Online
Live match highlighting, capture groups, all JS flags. No signup, browser-based.
Open Regex Tester