Free Online Regex Tester & Builder
Test and debug your JavaScript regular expressions in real time with live match highlighting, capture groups, and an instant plain-English explanation.
Enter a regex and test string to see matches
Common Patterns
What is a Regular Expression?
A regular expression (regex or regexp) is a powerful sequence of characters that defines a search pattern. Originally rooted in formal language theory, regex has become an indispensable tool for developers, data analysts, and system administrators worldwide. Regular expressions are used for pattern matching within strings — enabling tasks like input validation (emails, phone numbers, passwords), text searching and extraction, find-and-replace operations, and data parsing. In JavaScript, regex patterns are enclosed between forward slashes (/pattern/flags) and can be tested with methods like .test(), .match(), and .replace(). While regex syntax can appear cryptic at first, learning the fundamentals — character classes, quantifiers, anchors, and groups — unlocks the ability to process text with surgical precision. RegexLab makes this learning process interactive by providing instant feedback as you type.
How to Use RegexLab
- 1 Enter your regex — Type your regular expression pattern in the input field at the top. Toggle flags (g, i, m, s, u) as needed.
- 2 Paste your test string — Add the text you want to test against in the test string area. Matches highlight instantly.
- 3 Review matches — Check the Matches panel for details: each match's value, position, and capture groups.
- 4 Read the explanation — Switch to the Explanation tab for a plain-English breakdown of your pattern.
- 5 Use Replace mode — Enable it to preview string replacements with your regex live. Use $1, $2 for group references.
Regex Cheat Sheet
Anchors & Boundaries
| Symbol | Meaning | Example |
|---|---|---|
| ^ | Start of string | ^Hello |
| $ | End of string | world$ |
| \b | Word boundary | \bword\b |
| \B | Non-word boundary | \Bend |
Quantifiers
| Symbol | Meaning | Example |
|---|---|---|
| * | 0 or more | ab*c |
| + | 1 or more | ab+c |
| ? | 0 or 1 | colou?r |
| {n} | Exactly n times | \d{3} |
| {n,m} | Between n and m | \d{2,4} |
Character Classes
| Symbol | Meaning | Example |
|---|---|---|
| . | Any character (except newline) | a.c |
| \d | Digit [0-9] | \d+ |
| \w | Word char [a-zA-Z0-9_] | \w+ |
| \s | Whitespace | \s+ |
| [abc] | Any of a, b, c | [aeiou] |
| [^abc] | Not a, b, or c | [^0-9] |
Groups & Assertions
| Symbol | Meaning | Example |
|---|---|---|
| (abc) | Capture group | (\d+)-(\d+) |
| (?:abc) | Non-capture group | (?:ab)+ |
| a|b | Alternation (or) | cat|dog |
| (?=abc) | Positive lookahead | \d(?=px) |
| (?!abc) | Negative lookahead | \d(?!px) |
| (?<=abc) | Positive lookbehind | (?<=\$)\d+ |