Regex Tester

Text

Test and debug regular expressions with live matching

//
Test String

Try an example:

Quick Reference

Characters

.Any character (except newline)
\dDigit [0-9]
\wWord char [a-zA-Z0-9_]
\sWhitespace
\bWord boundary

Quantifiers

*0 or more
+1 or more
?0 or 1
{n}Exactly n
{n,m}Between n and m

Groups & Lookaround

(abc)Capture group
(?:abc)Non-capturing group
(?<name>abc)Named group
(?=abc)Lookahead
(?!abc)Negative lookahead

Anchors & Alternation

^Start of string/line
$End of string/line
a|bAlternation (a or b)
[abc]Character class
[^abc]Negated class

What is a Regular Expression?

A regular expression (regex or regexp) is a pattern that describes a set of strings. Originally developed by mathematician Stephen Kleene in the 1950s, regular expressions are now a fundamental tool in programming, text processing, and data validation.

In JavaScript, regular expressions are created with the RegExp constructor or literal syntax /pattern/flags. They power methods like .match(), .replace(), .test(), and .split().

Regex Syntax Guide

Regular expressions are built from literal characters and metacharacters. Here are the key building blocks:

  • Character classes like \d (digit), \w (word character), and [a-z] (ranges) match categories of characters.
  • Quantifiers like *, +, ?, and {n,m} control how many times a pattern repeats. Append ? for lazy (non-greedy) matching.
  • Groups and backreferences use (pattern) to capture submatches and \1 or $1 to reference them in replacements.
  • Lookahead and lookbehind(?=...) and (?<=...) — assert that what follows or precedes the current position matches a pattern, without including it in the match.

Common Regex Patterns

Email address[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}
URLhttps?:\/\/[\w.-]+(?:\.[a-zA-Z]{2,})(?:\/[^\s]*)?
IPv4 address\b(?:\d{1,3}\.){3}\d{1,3}\b
Date (YYYY-MM-DD)\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
Hex colour#(?:[0-9a-fA-F]{3}){1,2}\b
UUID[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
Phone (US)\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
HTML tag<\/?[a-zA-Z][\w-]*(?:\s[^>]*)?\/?>

Frequently Asked Questions

What is a regular expression (regex)?+

A regular expression is a sequence of characters that defines a search pattern. It is used for pattern matching within strings — finding, extracting, validating, or replacing text. Regular expressions are supported in virtually every programming language and many text editors.

What do the flags g, i, m, s, and u mean?+

g (global) finds all matches instead of stopping at the first. i (case-insensitive) ignores letter casing. m (multiline) makes ^ and $ match the start/end of each line, not just the entire string. s (dotall) makes . match newline characters. u (unicode) enables full Unicode matching, including surrogate pairs and Unicode property escapes.

What is a capture group?+

A capture group is a portion of the regex enclosed in parentheses ( ). It captures the matched text so you can reference it later — in replacement strings as $1, $2, etc., or in code via the match array. Named groups use the syntax (?<name>...) and can be referenced as $<name> in replacements.

Is this regex tester safe to use with sensitive data?+

Yes. This tool runs entirely in your browser using JavaScript's native RegExp engine. No data is sent to any server. Your patterns and test strings are processed locally and optionally saved to sessionStorage for convenience.

Why does my regex work differently in different languages?+

Regex flavors vary between languages. JavaScript's regex engine does not support lookbehind in older browsers, possessive quantifiers, or atomic groups. Features like \b word boundaries, Unicode categories (\p{L}), and backreferences may behave differently. This tester uses JavaScript's native RegExp, so results match what you'd get in Node.js or browser JavaScript.

Built With

This tester uses JavaScript's native RegExp engine — the same engine your code runs against.