Regex Tester Online

Test regular expressions with real-time highlighting.

Regular Expression
/ / g
Test String
Match Output

Type a regex pattern in the pattern box and test text below it — matches are highlighted in real time as you type. The Captured Groups table shows each match with its group values. All processing runs in your browser; nothing is sent to any server.

What is a regular expression?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Regex is used in virtually every programming language for string searching, validation, parsing, and replacement. The JavaScript engine (ECMAScript) used here follows the same rules as new RegExp(pattern, flags) in the browser.

Regex flags

g — global
Find all matches in the string. Without g, only the first match is returned.
i — case-insensitive
Match both uppercase and lowercase letters. /hello/i matches "Hello", "HELLO", "hElLo".
m — multiline
^ and $ match the start and end of each line rather than the entire string.
s — dotAll
The . metacharacter matches any character including newline (\n). Without s, . does not match newlines.

Common regex patterns

Quick reference
\d          Digit 0–9
\w          Word character (letter, digit, underscore)
\s          Whitespace (space, tab, newline)
\b          Word boundary
.           Any character except newline (with /s flag: including newline)
^           Start of string (with /m: start of line)
$           End of string (with /m: end of line)
*           0 or more (greedy)
+           1 or more (greedy)
?           0 or 1 (or makes * + ? lazy)
{n,m}       Between n and m times
(abc)       Capturing group
(?:abc)     Non-capturing group
[a-z]       Character class
[^a-z]      Negated character class
Common patterns
Email:    ^[\w.-]+@[\w.-]+\.\w{2,}$
URL:      https?://[\w./-]+
Date:     \d{4}-\d{2}-\d{2}
IPv4:     \b(?:\d{1,3}\.){3}\d{1,3}\b
Hex color: #[0-9a-fA-F]{3,6}

Code examples

JavaScript
const pattern = /(\w+)@(\w+\.\w+)/g;
const text = 'Contact [email protected] or [email protected]';

let match;
while ((match = pattern.exec(text)) !== null) {
  console.log(`Full: ${match[0]}, User: ${match[1]}, Domain: ${match[2]}`);
}

// Replace all emails
const redacted = text.replace(pattern, '[REDACTED]');
Python
import re

pattern = r'(\w+)@(\w+\.\w+)'
text = 'Contact [email protected] or [email protected]'

for match in re.finditer(pattern, text):
    print(f"Full: {match.group(0)}, User: {match.group(1)}")

Frequently asked questions

What regex engine does this tester use?
JavaScript's built-in RegExp (ECMAScript). Results will match what you get in Node.js and all modern browsers.
How do I match a literal dot, bracket, or other special character?
Escape the special character with a backslash. The special characters that need escaping are: . * + ? ^ $ { } [ ] | ( ) \
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, ?) match as much as possible. Lazy quantifiers (*?, +?, ??) match as little as possible. For example, /<.+>/ on <a>text</a> matches the whole string (greedy), while /<.+?>/ matches just <a>.
What are capturing groups and how do I access them?
Parentheses () create capturing groups. In JavaScript, match[1], match[2] etc. access them. Use (?:) for a non-capturing group when you only need grouping for quantifiers or alternation.

Related tools