Regex Tester & Validator

Write, test, and debug regular expressions with real-time match highlighting — entirely in your browser

g
Test String
Matches: 0 Groups: 0
Replace
Result
Match Details
No matches found. Type a pattern and test string above.
Character Classes
.Any character (except newline)
\dDigit [0-9]
\DNon-digit
\wWord character [a-zA-Z0-9_]
\WNon-word character
\sWhitespace
\SNon-whitespace
[abc]Character set: a, b, or c
[^abc]Negated set: not a, b, or c
[a-z]Range: a through z
Quantifiers
*0 or more
+1 or more
?0 or 1 (optional)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?0 or more (lazy)
+?1 or more (lazy)
Anchors & Boundaries
^Start of string / line
$End of string / line
\bWord boundary
\BNon-word boundary
Groups & Lookaround
(abc)Capture group
(?:abc)Non-capturing group
(?<n>)Named capture group
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=)Positive lookbehind
(?<!)Negative lookbehind
a|bAlternation (or)

What is a Regular Expression (Regex)?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Regular expressions are one of the most powerful tools in programming for working with text. They let you search for patterns in strings, validate user input, extract structured data from unstructured text, and perform complex find-and-replace operations — all with a single expression.

Regular expressions are supported in virtually every programming language including JavaScript, Python, Java, C#, Go, Ruby, PHP, and Perl, as well as in command-line tools like grep, sed, and awk. While the syntax varies slightly between flavors, the core concepts — character classes, quantifiers, groups, and anchors — are universal.

The concept of regular expressions originates from formal language theory developed by mathematician Stephen Kleene in the 1950s. Ken Thompson brought them into computing by implementing them in the QED text editor and later in Unix tools. Today, regex is an indispensable skill for developers, data scientists, system administrators, and anyone who works with text data at scale.

How Regular Expressions Work

At its core, a regex engine reads a pattern character by character and tries to match it against an input string. The engine walks through the string one position at a time, attempting to find a sequence of characters that satisfies the entire pattern. If a match attempt fails at any point, the engine backtracks and tries the next starting position.

Character Matching

Literal characters in a pattern match themselves. The pattern cat matches the exact string "cat" within any text. Special characters (called metacharacters) have special meanings: . matches any character, \d matches any digit, and \w matches any word character (letter, digit, or underscore).

Quantifiers

Quantifiers specify how many times a character or group should repeat. * means zero or more, + means one or more, ? means zero or one, and {n,m} means between n and m times. By default, quantifiers are greedy — they match as much as possible. Adding ? after a quantifier makes it lazy, matching as little as possible.

Groups and Capture

Parentheses () create capture groups that let you extract specific parts of a match. For example, (\d{4})-(\d{2})-(\d{2}) applied to "2024-03-15" captures "2024", "03", and "15" as separate groups. Named groups like (?<year>\d{4}) make your patterns more readable and maintainable.

Anchors

^ asserts the position at the start of the string (or line in multiline mode), while $ asserts the end. \b marks a word boundary — the position between a word character and a non-word character. These anchors don't match characters themselves but rather positions in the string.

Common Regex Use Cases

Input Validation

Validate email addresses, phone numbers, zip codes, credit card numbers, passwords, and other user inputs. Regex can enforce format requirements before data reaches your backend or database.

Search & Extract

Find and extract structured data from unstructured text — URLs from web pages, dates from documents, error codes from log files, or specific fields from CSV and configuration files.

Find & Replace

Perform sophisticated text transformations — reformat dates, rename variables across a codebase, clean up whitespace, normalize data formats, or restructure text with capture group back-references.

Parsing & Tokenization

Split text into meaningful tokens for lexical analysis, syntax highlighting, Markdown processing, template engines, or any application that needs to understand the structure of text.

JavaScript Regex Flags Explained

Flags (also called modifiers) change how the regex engine interprets and applies a pattern. In JavaScript, flags are appended after the closing delimiter of the regex literal (/pattern/flags) or passed as the second argument to new RegExp(pattern, flags).

Flag Name Description
g Global Find all matches in the string, not just the first. Without this flag, the regex stops after the first match.
i Case-insensitive Makes the pattern match regardless of letter case. /abc/i matches "ABC", "Abc", "aBc", etc.
m Multiline Changes ^ and $ to match the start/end of each line, not just the entire string. Essential for line-by-line matching.
s DotAll Makes . match any character including newlines (\n, \r). By default, . does not match newline characters.
u Unicode Enables full Unicode matching. Treats the pattern and string as Unicode code points. Required for matching emoji and supplementary characters correctly.
y Sticky Matches only at the position indicated by lastIndex. Unlike global, it will not scan ahead — the match must start exactly at the expected position.

Features of This Regex Tester

  • Real-time match highlighting — Matches are highlighted directly in your test string as you type the pattern. Alternating colors (blue and green) distinguish adjacent matches, making it easy to see where one match ends and the next begins.
  • Capture group inspection — Every capture group (numbered and named) is displayed for each match in the details panel. See exactly what each group captured, along with match position and length.
  • Live replace preview — Enter a replacement string and see the result instantly. Supports all JavaScript replacement patterns: $1, $2 for numbered groups, $<name> for named groups, $& for the full match, and $` / $' for pre/post-match text.
  • All JavaScript flags — Toggle any combination of the six JavaScript regex flags (g, i, m, s, u, y) with a single click. Active flags are visually highlighted so you always know which modifiers are in effect.
  • Pattern validation — Invalid patterns are caught instantly with clear error messages. The input border turns red and the error message shows exactly what went wrong, helping you fix syntax issues quickly.
  • Preset patterns — One-click presets for common regex patterns (email, URL, IP address, date, hex color, phone number) with realistic sample test strings. Great for learning and quick validation tasks.
  • Quick reference — A collapsible reference panel with clickable tokens. Click any token to insert it into your pattern at the cursor position. Covers character classes, quantifiers, anchors, and groups.
  • 100% client-side — All processing happens entirely in your browser. Your patterns and test data are never transmitted to any server. The tool works offline after the initial page load.
  • No dependencies — Built with vanilla HTML, CSS, and JavaScript. No frameworks, no build tools, no third-party libraries. Loads instantly and runs on any modern browser.

Frequently Asked Questions

What is a regular expression (regex)?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Regular expressions are used for pattern matching within strings — finding, extracting, replacing, or validating text. They are supported in virtually every programming language including JavaScript, Python, Java, C#, Go, and Ruby, as well as in command-line tools like grep, sed, and awk.

Is this regex tester safe to use with sensitive data?

Yes. This tool processes everything entirely in your browser using JavaScript. Your patterns and test strings are never transmitted to any server. You can verify this by checking the browser's network tab — no requests are made when you test a pattern. The tool works offline after the initial page load.

What regex flags are supported?

This tool supports all standard JavaScript regex flags: g (global — find all matches), i (case-insensitive matching), m (multiline — ^ and $ match line boundaries), s (dotAll — dot matches newlines), u (unicode — full Unicode support), and y (sticky — match from lastIndex only).

What are capture groups in regex?

Capture groups are portions of a regex pattern enclosed in parentheses (). They let you extract specific parts of a match. For example, the pattern (\d{4})-(\d{2})-(\d{2}) applied to "2024-03-15" captures the year, month, and day as separate groups. Named groups use the syntax (?<name>...) for clearer code. This tool displays all capture groups for each match.

What is the difference between greedy and lazy matching?

Greedy quantifiers (*, +, {n,m}) match as much text as possible, while lazy quantifiers (*?, +?, {n,m}?) match as little as possible. For example, given the text "<b>bold</b>", the greedy pattern <.+> matches the entire string "<b>bold</b>", but the lazy pattern <.+?> matches just "<b>" and then "</b>" separately.

Why does my regex work differently in different languages?

While the core regex syntax is similar across languages, there are differences in supported features. For example, JavaScript does not support possessive quantifiers (++, *+) or atomic groups ((?>...)), which languages like Java and .NET do. Lookahead and lookbehind support also varies — JavaScript added lookbehind in ES2018, but older browsers may not support it. This tool uses the JavaScript regex engine built into your browser.

How do I use replacement patterns like $1 and $&?

In the replace field, you can use special replacement patterns. $1, $2, etc. insert the text captured by the corresponding numbered group. $<name> inserts a named group's capture. $& inserts the entire match. $` inserts the text before the match, and $' inserts the text after. $$ inserts a literal dollar sign. These patterns follow the JavaScript String.replace() specification.