Test regular expressions in real-time. See matches highlighted, extract groups, replace and explore a full cheatsheet.
//
Test String
Presets:
Matches
Replace
Cheatsheet
Enter a pattern above to see matches
Replace:
Replace result will appear here...
Anchors
^Start of string/line
$End of string/line
\bWord boundary
\BNot word boundary
Character Classes
.Any character (except newline)
\dDigit [0-9]
\DNot a digit
\wWord char [a-zA-Z0-9_]
\WNot a word char
\sWhitespace
\SNot whitespace
[a-z]Character range
[^abc]Not a, b, or c
Quantifiers
*0 or more (greedy)
+1 or more (greedy)
?0 or 1 (optional)
{n}Exactly n times
{n,m}Between n and m times
*?0 or more (lazy)
+?1 or more (lazy)
Groups & Lookaround
(abc)Capture group
(?:abc)Non-capture group
a|bAlternation (a or b)
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
Regular Expression Tester
A regular expression (regex or regexp) is a sequence of characters defining a search pattern. Used in virtually every programming language, regex is essential for text processing, validation, parsing and transformation.
Regex flags explained
g (global) — Find all matches, not just the first
i (case insensitive) — Match regardless of case
m (multiline) — ^ and $ match start/end of each line
s (dotAll) — . matches newline characters too
Frequently Asked Questions
What does .* mean in regex? +
. matches any character (except newline by default), and * means "zero or more" of the preceding element. So .* matches any sequence of characters. It's greedy — it will match as much as possible. Use .*? for lazy matching (as little as possible).
How do I match a literal dot or special character? +
Escape it with a backslash. To match a literal dot use \., a literal + use \+, a literal ( use \(, etc. Special characters that need escaping: . * + ? ^ $ { } [ ] | ( ) \
What is a capture group and how do I use $1? +
Parentheses create a capture group: (pattern). Each group gets a number starting at 1. In replacement strings, $1 refers to the first group's match. For example, pattern (\w+) (\w+) with replacement $2 $1 would swap two words.
Is this JavaScript regex or PCRE? +
This tester uses JavaScript's built-in RegExp engine. JS regex is mostly compatible with other flavours but has some differences from PCRE (PHP/Python). Notably, JS supports lookbehind (?<=) in modern browsers, but doesn't support PCRE-specific features like \K or recursive patterns.