.*

RegexLab

Advertisement

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.

Flags:
/ / g
0.00ms

Enter a regex and test string to see matches

Advertisement

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. 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. 2 Paste your test string — Add the text you want to test against in the test string area. Matches highlight instantly.
  3. 3 Review matches — Check the Matches panel for details: each match's value, position, and capture groups.
  4. 4 Read the explanation — Switch to the Explanation tab for a plain-English breakdown of your pattern.
  5. 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

SymbolMeaningExample
^Start of string^Hello
$End of stringworld$
\bWord boundary\bword\b
\BNon-word boundary\Bend

Quantifiers

SymbolMeaningExample
*0 or moreab*c
+1 or moreab+c
?0 or 1colou?r
{n}Exactly n times\d{3}
{n,m}Between n and m\d{2,4}

Character Classes

SymbolMeaningExample
.Any character (except newline)a.c
\dDigit [0-9]\d+
\wWord char [a-zA-Z0-9_]\w+
\sWhitespace\s+
[abc]Any of a, b, c[aeiou]
[^abc]Not a, b, or c[^0-9]

Groups & Assertions

SymbolMeaningExample
(abc)Capture group(\d+)-(\d+)
(?:abc)Non-capture group(?:ab)+
a|bAlternation (or)cat|dog
(?=abc)Positive lookahead\d(?=px)
(?!abc)Negative lookahead\d(?!px)
(?<=abc)Positive lookbehind(?<=\$)\d+

Frequently Asked Questions

Advertisement