PublicSoftTools
Tools16 min read·PublicSoftTools Team·May 2026

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:

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

  1. Open the Regex Tester
  2. Enter your regular expression in the Pattern field
  3. Select the flags you need (g, i, m, s, u)
  4. Paste or type your test string in the Test String area
  5. Matches are highlighted live. Scroll down to see match details: index, length, and captured groups

Regex Flags Reference

FlagNameEffect
gGlobalFind all matches, not just the first
iCase-insensitiveMatch regardless of letter case
mMultiline^ and $ match start/end of each line
sDotall. matches newline characters
uUnicodeTreat pattern and string as Unicode; required for emoji and non-BMP characters

Core Regex Syntax Reference

Character classes

PatternMatchesExample
.Any character except newline (with s flag: including newline)a.c matches “abc”, “a2c”
\dAny digit (0–9)\d+ matches “123”
\DAny non-digit\D matches “a”, “!”
\wWord character: a–z, A–Z, 0–9, underscore\w+ matches “hello_123”
\WNon-word characterMatches spaces, punctuation
\sWhitespace: space, tab, newline, return\s+ matches any run of whitespace
\SNon-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

QuantifierMeaningExample
*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

PatternMatches
^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary — position between \w and \W
\BNon-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\.com

The 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.

SyntaxTypeMatches
(?=…)Positive lookaheadPosition followed by pattern
(?!…)Negative lookaheadPosition NOT followed by pattern
(?<=…)Positive lookbehindPosition preceded by pattern
(?<!…)Negative lookbehindPosition 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.

Lazy matching is almost always what you want when extracting content between delimiters.

Debugging Regex That Isn't Matching

Test Regular Expressions Free Online

Live match highlighting, capture groups, all JS flags. No signup, browser-based.

Open Regex Tester