Regex Tester
Test and debug regular expressions with live matching, highlighting, and capture groups
Regular Expression
Test String
Results
Find & Replace
$& for full match, $1 $2 for capture groups, $` before, $' after
Regex Cheatsheet
Character Classes
. | Any character (except newline) |
\d | Digit [0-9] |
\D | Non-digit |
\w | Word character [a-zA-Z0-9_] |
\W | Non-word character |
\s | Whitespace |
\S | Non-whitespace |
[abc] | Any of a, b, or c |
[^abc] | Not a, b, or c |
[a-z] | Character range |
Anchors
^ | Start of string/line |
$ | End of string/line |
\b | Word boundary |
\B | Non-word boundary |
Quantifiers
* | 0 or more |
+ | 1 or more |
? | 0 or 1 (optional) |
{n} | Exactly n times |
{n,} | n or more times |
{n,m} | Between n and m times |
*? | Non-greedy * |
+? | Non-greedy + |
Groups & Lookaround
(abc) | Capture group |
(?:abc) | Non-capture group |
(?<name>abc) | Named capture group |
\1 | Backreference |
(?=abc) | Positive lookahead |
(?!abc) | Negative lookahead |
(?<=abc) | Positive lookbehind |
(?<!abc) | Negative lookbehind |
Special Characters
\n | Newline |
\t | Tab |
\r | Carriage return |
\\ | Escape special char |
| | Alternation (or) |
Flags
g | Global (find all) |
i | Case insensitive |
m | Multiline mode |
s | Dotall (. matches \n) |
u | Unicode mode |
Regex Tester - Test Regular Expressions Online
Test and debug regular expressions in real-time with our free online regex tester. See matches highlighted instantly, inspect capture groups, and learn regex with our built-in cheatsheet. All processing happens in your browser — your data stays private.
Features
- Real-time matching: See matches highlighted as you type
- Capture groups: View all captured groups with indices
- Find & Replace: Test replacement patterns with group references
- Common presets: Quick patterns for email, URL, IP, phone numbers
- All flags: Support for global, case-insensitive, multiline, dotall, and unicode flags
- Cheatsheet: Built-in regex reference guide
What is a Regular Expression?
A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. They're used in programming for string matching, validation, parsing, and text manipulation. Regex patterns can range from simple literal matches to complex patterns involving character classes, quantifiers, groups, and lookarounds.
Common Use Cases
check_circle Validation
Validate user input like email addresses, phone numbers, postal codes, URLs, and passwords against specific patterns.
search Search & Extract
Find and extract specific data from text, such as extracting all dates, phone numbers, or email addresses from a document.
find_replace Find & Replace
Perform complex find-and-replace operations, like reformatting dates, standardizing phone numbers, or cleaning up text.
code Parsing
Parse structured text like log files, CSV data, or markup languages to extract meaningful information.
Tips for Writing Better Regex
- Start simple: Begin with a basic pattern and add complexity gradually
- Be specific: Use character classes instead of
.when possible - Use anchors:
^and$prevent unexpected partial matches - Non-greedy matching: Add
?after quantifiers to match minimally - Test edge cases: Try empty strings, special characters, and boundary conditions
- Comment complex patterns: Use named groups for self-documenting regex
JavaScript Regex Methods
| Method | Description | Example |
|---|---|---|
test() |
Returns true if pattern matches | /\d/.test("abc123") → true |
match() |
Returns matches as array | "abc".match(/[a-z]/g) |
matchAll() |
Returns iterator of all matches | "test".matchAll(/t/g) |
replace() |
Replace matches | "hi".replace(/i/, "ey") |
split() |
Split string by pattern | "a,b;c".split(/[,;]/) |
search() |
Returns index of first match | "hello".search(/l/) → 2 |
Privacy First
All regex testing happens directly in your browser using JavaScript. Your patterns and test strings never leave your device — we don't store, track, or log any data. This makes our tool safe for testing sensitive patterns like passwords or private data formats.