Tools

Regex

Pattern matching — anchors, classes, quantifiers, groups.

Character classes

.Any char except newline
\d \DDigit / non-digit
\w \WWord char / non-word
\s \SWhitespace / non-ws
[abc]a, b, or c
[^abc]Not a, b, or c
[a-z]Range

Anchors

^Start of line
$End of line
\bWord boundary
\BNon-boundary

Quantifiers

*0 or more
+1 or more
?0 or 1
{3}Exactly 3
{2,5}Between 2 and 5
{2,}2 or more
*?Lazy (non-greedy)

Groups & lookaround

(abc)Capture group
(?:abc)Non-capturing
(?<name>x)Named group
a|bAlternation
(?=x)Positive lookahead
(?!x)Negative lookahead
(?<=x)Positive lookbehind

Common patterns

# email (simple)
^[\w.+-]+@[\w-]+\.[\w.-]+$

# URL
https?://[^\s]+

# IPv4
\b(\d{1,3}\.){3}\d{1,3}\b

# strip HTML tags
<[^>]+>