Table of Content

Predefined Regex

IP

v4

\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

v6

(?<![:.\w])(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}(?![:.\w])

MAC address

^[a-fA-F0-9]{2}(:[a-fA-F0-9]{2}){5}$

Password

Special characters are limited

^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$ %^&*-]).{8,}$

URL

matches URLS starting with http

https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)

Semantiv versioning

^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$

Reference Table

Common Tokens

PatternDescription
[abc]A single character of: a, b or c
[^abc]A character except: a, b or c
[a-z]A character in the range: a-z
[^a-z]A character not in the range: a-z
[a-zA-Z]A character in the range: a-z or A-Z
.Any single chracter
a|bAlternate - match either a or b
\sAny whitespace character
\SAny non-whitespace character
\dAny digit
\DAny non-digit
\wAny word character
\WAny non-word character
(?:...)Match everything enclosed
(...)Capture everything enclosed
a?Zero or one of a
a*Zero or more of a
a+One or more of a
a{3}Exactly 3 of a
a{3,}3 or mor of a
a{3,6}Between 3 and 6 of a
^Start of string
$End of string
\bA word boundary
\BNon-word boundary

General Tokens

PatternDescription
\nNewline
\rCarriage return
\tTab
\0Null character

Anchors

PatternDescription
\GStart of match
^Start of string
$End of string
\AStart of string
\ZEnd of string
\zAbsolut end of string
\bA word boundary
\BNon-word boundary

Meta Sequences

PatternDescription
.Any single chracter
a|bAlternate - match either a or b
\sAny whitespace character
\SAny non-whitespace character
\dAny digit
\DAny non-digit
\wAny word character
\WAny non-word character
\XAny Unicode sequence, linebreks included
\CMAtch one data unit
\RUnicode newlines
\NMatch anything but a newline
\vVertical whitespace character
\VNegative of \v
\hHorizontal whitespace character
\HNegative of \h
\KReset match
\#Match subpattern number #
\pXUnicode property X
\p{...}Unicode preoperty or script category
\PXNegation of \pX
\P{...}Negation of p{...}
\Q...\EQuote; treat as literals
\k{name}Match subpattern name
\k<name>Match subpattern name
\k'name'Match subpattern name
\gnMatch nth subpattern
\g{n}Match nth subpattern
\g{-n}Match text the nth relative previouse subpattern matched
\g<n>Recurse nth capture group
\g<+n>Recurse nth relative upcoming subpattern
\g'n'Recurse nth capture group
\g'+n'Recurse nth relative upcoming subpattern
\g{letter}Match previously-named capture group letter
\g<letter>Match previously-named capture group letter
\g'letter'Match previously-named capture group letter
\xYYHex character YY
\x{YYYY}Hex character YYYY
\dddOctal character ddd
\cYControl character Y
[\b]Backspace character
\Makes any character literal

Quantifiers

PatternDescription
a?Zero or one of a
a*Zero or more of a
a+One or more of a
a{3}Exactly 3 of a
a{3,}3 or mor of a
a{3,6}Between 3 and 6 of a
a*Greedy quantifier
a*?Layz quantifier
a*+Possessiv quantifier

Group Constructs

PatternDescription
(?:...)Match everything enclosed
(...)Capture everything enclosed
(?>...)Atomic group (non-capturing)
(?|...)Duplicate/reset subpattern group number
(?#...)Comment group
(?'name'...)Named Capturing Group
(?<name>...)Named Capturing Group
(?P<name>...)Named Capturing Group
(?imsxUJnxx)Inline modifiers
(?imsxUJnxx:...)Localized inline modifiers
(?(1)yes|no)Conditional statement
(?(R)yes|no)Conditional statement
(?(R#)yes|no)Recursive conditional statement
(?(R&name)yes|no)Conditinal statement
(?(?=...)yes|no)Lookahead conditional
(?(?<=...)yes|no)Lookbehind conditional
(?R)Recurse entrie pattern
(?1)Recurse first subpattern
(?+1)Recurse first relative subpattern
(?&name)Recurse subpattern name
(?P=name)Match subpattern name
(?P>name)Recurse subpattern called name
(?(DEFINE)...)Pre-define patterns before using them
(?=...)Positive lookahead
(?!...)Negative lookahead
(?<=...)Positive lookbehind
(?<!...)Negative lookbehind
(*ACCEPT)Control verb
(*FAIL)Control verb
(*MARK:NAME)Control verb
(*PRUNE)Control verb
(*SKIP)Control verb
(*THEN)Control verb
(*UTF)Pattern modifier
(*UTF8)Pattern modifier
(*UTF16)Pattern modifier
(*UTF32)Pattern modifier
(*UCP)Pattern modifier
(*CR)Line break modifier
(*LF)Line break modifier
(*CRLF)Line break modifier
(*ANYCRLF)Line break modifier
(*ANY)Line break modifier
\RLine break modifier
(*BSR_ANYCRLY)Line break modifier
(*BSR_UNICODE)Line break modifier
(*LIMIT_MATCH=x)Regex engine modifier
(*LIMIT_RECURSION=d)Regex engine modifier
(*NO_AUTO_POSSESS)Regex engine modifier
(*NO_START_OPT)Regex engine modifier

Character Classes

PatternDescription
[abc]A single character of: a, b or c
[^abc]A character except: a, b or c
[a-z]A character in the range: a-z
[^a-z]A character not in the range: a-z
[a-zA-Z]A character in the range: a-z or A-Z
[[:alnum:]]Letter and diget
[[:ascii:]]ASCII codes 0-127
[[:blank:]]Space or tab only
[[:cntrl:]]Control character
[[:digit:]]Decimal digit
[[:graph:]]Visible character (not space)
[[:lower:]]Lowercase letter
[[:print:]]Visible character
[[:punct:]]Visible punctuation character
[[:space:]]Whitespace
[[:upper:]]Uppercase letter
[[:word:]]Word character
[[:xdigit:]]Hexadecimal digit
[[:<:]]Start of word
[[:>:]]End of word

Flags Modifiers

PatternDescription
gGlobal
mMultiline
iCase insensitive
xIgnore whitespace /verbose
sSingle line
uUnicode
XeXtra
UUngreedy
AAnchor
JDuplicate group name

Substituion

PatternDescription
$1Contents in capture group 1
${foo}Contens in capture group foo
\x20Hexadecimal replacement values
\x{06fa}Hexadecimal replacement values
\tTab
\rCarriage return
\fFrom-feed
\UUppercase Transformation
\LLowercase Transformation
\ETerminate any Transformation