Live Matching · Groups · Common Patterns

Regex Tester

Test regular expressions in real time. See all matches highlighted, inspect capture groups, toggle flags, and load common patterns for emails, URLs, dates, and more.

Live Highlighting
Capture Groups
Flags: g, i, m, s
Common Patterns
Ad · 728×90
Regex Tester
JavaScript RegExp · Live matching
Regular Expression
/ /
Common Patterns
Test String
Match Highlights
Ad · 300×600
Ad · 728×90

Regular Expressions Quick Reference

Regular expressions (regex) are patterns for matching text. The syntax below applies to JavaScript RegExp (used by this tester) and is largely compatible with Python, Java, and most modern languages.

Character Classes
\d = digit [0-9]. \w = word [a-zA-Z0-9_]. \s = whitespace. \D, \W, \S = negated. [abc] = a, b, or c. [^abc] = not a, b, or c. [a-z] = lowercase letter. . = any char except newline.
Quantifiers
* = 0 or more. + = 1 or more. ? = 0 or 1. {n} = exactly n. {n,} = n or more. {n,m} = between n and m. Add ? after to make lazy (minimal): *? +? ?? {n,m}?
Anchors & Boundaries
^ = start of string (or line with m flag). $ = end of string (or line with m flag). \b = word boundary. \B = non-word boundary. Use ^ and $ together to match the entire string.
Groups & Lookaround
(abc) = capture group. (?:abc) = non-capturing group. (?<name>abc) = named group. | = alternation (or). (?=abc) = lookahead. (?!abc) = negative lookahead. (?<=abc) = lookbehind.
Frequently Asked Questions
What is a regular expression (regex)?+
A regular expression is a sequence of characters that defines a search pattern. Regex is used to find, validate, and manipulate text. A pattern like \d{3}-\d{4} matches phone number segments (three digits, dash, four digits). Regex is supported in virtually every programming language and text editor. The syntax has a common core (derived from Perl) with some language-specific variations. This tester uses JavaScript's RegExp engine.
What do the regex flags g, i, m, and s do?+
g (global): Find all matches, not just the first. Without g, only the first match is returned. i (case-insensitive): Match [a-z] and [A-Z] interchangeably. m (multiline): ^ and $ match start/end of each line, not just start/end of the entire string. s (dotAll): The dot (.) matches newlines too. By default, dot doesn't match \n. Enable dotAll when matching across multiple lines with dot.
How do I write a regex for email validation?+
A basic email regex: [a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,} (use i flag for case-insensitive). This matches: local part (letters, digits, dots, underscores, percent, plus, minus) + @ + domain + . + TLD (2+ letters). No regex perfectly validates all valid email addresses per RFC 5321/5322, which allows many edge cases. For real validation, combine basic regex with sending a confirmation email. The HTML5 email input type has a reasonable built-in validation pattern.
What is a capture group and how do I use it?+
A capture group (pattern) saves the matched text for later use. Example: (\d{4})-(\d{2})-(\d{2}) matches dates like 2026-05-13 and captures year, month, day as groups 1, 2, 3. In JavaScript: match[1]='2026', match[2]='05', match[3]='13'. Named groups (?<year>\d{4}) let you access captures by name: match.groups.year. Non-capturing groups (?:pattern) group without saving, useful with alternation: (?:cat|dog)s matches both "cats" and "dogs".
How do I match a literal dot or other special characters?+
In regex, many characters have special meanings: . * + ? ^ $ { } [ ] | ( ) \. To match them literally, escape with a backslash: \. matches a literal dot, \* matches a literal asterisk. Example: to match "3.14", use 3\.14. Without escaping, 3.14 would match "3X14", "3_14", etc. (since . matches any character). Common escapes: \. \* \+ \? \( \) \[ \] \{ \} \\ \^
What is greedy vs lazy matching?+
Greedy quantifiers (*, +, {n,m}) match as much as possible. Lazy quantifiers (*?, +?, {n,m}?) match as little as possible. Example with HTML: <.+> on "<b>text</b>" greedy matches the entire "<b>text</b>". <.+?> lazy matches just "<b>". Use lazy matching when you want the smallest possible match — common in HTML parsing, where greedy would consume from the first opening tag to the last closing tag.
How do I use regex in JavaScript?+
Two ways to create: Literal: const re = /pattern/flags. Constructor: const re = new RegExp('pattern', 'flags'). Key methods: re.test(str) → returns true/false. str.match(re) → array of matches (or null). str.matchAll(re) → iterator of all match objects (requires g flag). str.replace(re, replacement) → returns new string. str.split(re) → splits into array. Use matchAll for complex patterns with capture groups across all matches.
How do I match a URL with regex?+
A reasonable URL regex: https?:\/\/[^\s/$.?#].[^\s]* matches http:// or https://, followed by a non-whitespace domain, followed by any non-whitespace path. More precise: https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&=]*). Complete URL validation is notoriously difficult with regex — use the URL constructor in JavaScript (new URL(str)) which throws on invalid URLs.
What is a lookahead and lookbehind?+
Lookaround assertions match a position, not characters — they don't consume text. Positive lookahead (?=x): match if followed by x. \d+(?= dollars) matches numbers followed by " dollars". Negative lookahead (?!x): match if NOT followed by x. \d+(?! dollars) matches numbers not followed by " dollars". Positive lookbehind (?<=x): match if preceded by x. (?<=\$)\d+ matches numbers after a dollar sign. Negative lookbehind (?<!x): match if NOT preceded by x. Lookbehind is not supported in Safari before version 16.4.
How do I match multiple lines with regex?+
Two different scenarios: (1) Match ^ and $ at each line boundary — enable the m (multiline) flag. Now ^ matches start of each line and $ matches end of each line, not just the whole string. (2) Match content that spans multiple lines — enable the s (dotAll) flag so that . matches \n too. Without s flag, [\s\S]* is a common workaround that matches any character including newlines. Combine both flags when you need both behaviors: multiline anchors AND cross-line matching.