Regex Flavors Guide

Feature Comparison

FeaturePCRE/PHPPython reJavaScript
Named groups(?P<n>...)(?P<n>...)(?<n>...)
Lookbehind(?<=...)(?<=...)ES2018+
Recursive patterns(?R)NoNo
Unicode props\p{L}regex pkg\p{L} ES2018
Atomic groups(?>...)NoNo
Possessive quantifiers*+, ++NoNo
Inline flags(?i)(?i)No
Dotall mode(?s) or /sre.DOTALL/s ES2018

Named Groups

LanguageSyntaxAccess
PCRE / PHP(?P<year>\d{4})$matches['year']
Python(?P<year>\d{4})m.group('year')
JavaScript(?<year>\d{4})m.groups.year
Go(?P<year>\d{4})m[re.SubexpIndex("year")]

Common Patterns

PatternRegex
Email^[^\s@]+@[^\s@]+\.[^\s@]+$
URLhttps?://[^\s/$.?#].[^\s]*
IPv4(\d{1,3}\.){3}\d{1,3}
Date (YYYY-MM-DD)\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
Hex color#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})
UUID[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}