Test and debug regular expressions in real time. See matches highlighted, group captures, and test against multiple lines.
Regular Expression Tester
//
Matches
Capture Groups
Ad · 336x280
Regular Expressions Explained
A regular expression (regex) is a pattern that describes a set of strings. Regex is used in every programming language for text search, validation, extraction, and replacement. Learning regex is one of the highest-leverage skills for any developer or data professional.
Regex Quick Reference
. — Any character except newline
\d — Digit [0-9] | \w — Word character [A-Za-z0-9_] | \s — Whitespace
^ — Start of string/line | $ — End of string/line
+ — One or more | * — Zero or more | ? — Zero or one
{n,m} — Between n and m repetitions
(abc) — Capture group | (?:abc) — Non-capturing group
.* matches zero or more of any character (can match empty string). .+ matches one or more (requires at least one character). This matters in greedy matching: .* will match even if there's nothing there, while .+ fails on an empty string. Both are greedy by default — add ? to make them lazy (.*? matches as few characters as possible).
Add the i flag: /pattern/i in JavaScript, re.compile('pattern', re.IGNORECASE) in Python, /pattern/i in Ruby, (?i) inline modifier in Java/PCRE. With the i flag, [a-z] matches both upper and lowercase, and literal letters match their case variant.
Greedy (default): .* matches as much as possible. Given 'start middle end', <.*> matches 'middle' (the whole thing). Lazy: .*? matches as little as possible. <.*?> matches '' only. Add ? after a quantifier to make it lazy: +? *? {n,}?. Lazy is usually what you want when extracting HTML tags or quoted strings.
Escape with backslash. A dot . normally matches any character; \. matches a literal dot. Same for +, *, ?, ^, $, {, }, [, ], (, ), |, and /. In JavaScript strings, you need double backslash: new RegExp('https://\\w+\\.com') — the first \ escapes the backslash in the string, leaving a single \ for the regex engine. Using regex literals /pattern/ avoids this: /https:\/\/\w+\.com/.