Regex Guide for Developers
Complete guide to regular expressions with practical examples and patterns.
Real-time · 26 features · AI explain · Unit tests · Diff mode · JS/Python/PHP · 100% browser
A regular expression (regex) is a sequence of characters that defines a search pattern. Used for validation, parsing, text manipulation, and data extraction in virtually every programming language — JavaScript, Python, PHP, Java, and more.
Type your regex pattern in the input field. Matches highlight in real-time in the test text panel. Use the flags (g/i/m/s/u/y) to modify matching behavior. Switch between Test, Replace, Unit Test, Diff, and Multi-string modes using the tabs above.
A regular expression (regex) is a sequence of characters that defines a search pattern. Used for string matching, validation, parsing, and text manipulation in virtually every programming language.
g = global (find all matches), i = case-insensitive, m = multiline (^ and $ match line start/end), s = dotAll (. matches newline), u = unicode mode, y = sticky (match from lastIndex position).
Parentheses () create a capture group. The content matched inside is captured and accessible as group 1, 2, etc. Named groups use (?<name>...) syntax and are accessible by name.
Greedy (default): .* matches as much as possible. Lazy: .*? matches as little as possible. Add ? after a quantifier to make it lazy: +?, *?, {n,m}?.
Lookaheads assert what follows without consuming characters. (?=x) positive: position must be followed by x. (?!x) negative: position must NOT be followed by x. Lookbehind (?<=x) and (?<!x) work the same way but look behind.
regex.test(str) returns true/false. str.match(regex) returns an array of matches (or null). str.matchAll(regex) returns an iterator of all matches with groups. str.replace(regex, replacement) replaces matches.