Advertisement

Regex Tester

Test, debug and replace regular expressions with live match highlighting, group capture, replace mode and a pattern library.

/ /
No capture groups or no matches.
Matches will appear here.

Understanding Regular Expressions

Regular expressions (regex) are patterns used to match, search, and manipulate text. They are supported in virtually every programming language — JavaScript, Python, Java, Ruby, PHP, Go — and in command-line tools like grep, sed, and awk. Once you understand the core syntax, regex becomes one of the most powerful tools in any developer or data analyst's toolkit.

Core Regex Syntax Reference

Character classes: [abc] matches a, b, or c. [a-z] matches any lowercase letter. [^abc] matches anything except a, b, c. \d matches any digit (0-9). \w matches word characters (letters, digits, underscore). \s matches whitespace.

Quantifiers: * matches 0 or more. + matches 1 or more. ? matches 0 or 1 (makes it optional). {3} matches exactly 3. {2,5} matches between 2 and 5. Adding ? after a quantifier makes it lazy (matches as little as possible).

Anchors and boundaries: ^ matches the start of a line. $ matches the end.  matches a word boundary. These are critical for avoiding partial matches — cat matches "concatenate" but cat only matches the standalone word "cat".

Common Regex Use Cases

Email validation: ^[\w.-]+@[\w.-]+\.\w{2,}$. US phone numbers: ^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$. URLs: https?://[\w-]+(\.[\w-]+)+[^\s]*. Dates (MM/DD/YYYY): ^(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/\d{4}$. Use this tester to experiment with patterns against your real data before implementing them in code.

Frequently Asked Questions

What is a regular expression (regex)?
A regular expression is a sequence of characters that defines a search pattern. It is used to find, match, extract, or replace text in strings. Regex is supported in virtually every programming language including JavaScript, Python, PHP, Java, and most text editors.
What do the regex flags mean?
The most common flags are: g (global — find all matches, not just first), i (case-insensitive — match regardless of upper/lowercase), m (multiline — ^ and $ match start/end of each line), and s (dotAll — dot matches newline characters too).
Why is my regex not matching?
Common issues: forgetting to escape special characters like . * + ? ( ) [ ] { } \ ^ $, using the wrong flags (missing g for all matches), and anchor misuse (^ and $ mean start/end of string unless multiline flag is set). Use the preset examples in the tester to learn the patterns.
✓ Link copied