Regular expressions pcre2 cheatsheet
Regular expressions pcre2: Common patterns
12 common Regular expressions pcre2 tasks.
Email address (simple)
A permissive check for [email protected]. Fully validating email is impractical, so confirm addresses by sending a message.
^[^\s@]+@[^\s@]+\.[^\s@]+$
IPv4 address (shape only)
Match four groups of 1 to 3 digits. It doesn't check that each is 255 or less.
\b(?:\d{1,3}\.){3}\d{1,3}\b
ISO date
Match dates like 2026-10-30. It doesn't check that the month or day are valid.
\d{4}-\d{2}-\d{2}
UUID
Match a UUID in the standard 8-4-4-4-12 format.
[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}
Semantic version
Match versions like 1.4.2, 2.0.0-beta.1 or 1.0.0+build.5.
^\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?$
Double-quoted string with escapes
Match a quoted string that may contain escaped quotes.
"(?:[^"\\]|\\.)*"
Trim whitespace
Match leading and trailing whitespace. Replace matches with nothing to trim.
^\s+|\s+$