. |
Any character, except newline |
---|---|
\c |
Control Character |
\w |
Word |
\d |
Digit |
\x |
Hexadecimal Digit |
\O |
Octal Digit |
\s |
Whitespace |
\W |
Not word |
\D |
Not digit |
\S |
Not whitespace |
[abc] |
Any of a, b, or c |
[a-e] |
Characters between a and e |
[1-9] |
Digit between 1 and 9 |
^abc |
Start with abc |
---|---|
abc$ |
End with abc |
^ |
Start of string, or start of line in multi-line pattern. |
\A |
Start of string |
$ |
End of string, or end of line in multi-line pattern |
\Z |
End of string |
\b |
Word Boundary |
\B |
Not Word Boundary |
\< |
Start of word |
> |
End of word |
\. \* \\ |
Escape special character used by regex |
---|---|
\t |
Tab |
\n |
Newline |
\r |
Carriage return |
\v |
Vertical tab. |
\f |
Form Feed. |
\xxx |
Octal character xxx |
\xhh |
Hex character hh. |
(abc) |
Capture group |
---|---|
`(a | b)` |
(?:...) |
Passive (non-capturing) group |
a* |
Match 0 or more |
---|---|
a+ |
Match 1 or more |
a? |
Match 0 or 1 |
a{5} |
Match exactly 5 |
a{,3} |
Match up to 3 |
a{3,} |
Match 3 or more |
a{1,3} |
Match between 1 and 3 |
g |
global match |
---|---|
i |
Case insensitive match |
m |
Multiple line match |
s |
Treat as single line |
x |
Allow comments and white space in pattern |
e |
Eveluate replacement |
U |
Ungreedy match |
?= |
Lookahead assertion |
---|---|
?! |
Negative lookahead assertion |
?<= |
Lookbehind assertion |
?!= or ?<! |
Negative Lookbehind assertion |
?> |
Once-only Subexpression |
?() |
Condition [if then] |
`?() | ` |
?# |
Comment |
([^\s]+(?=.(jpg|gif|png)).\2)
(^[1-9]{1}|[1−4]1[0−9]1|^50$)
(#?([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?)
([A-Za-z0-9-]+)
Matches 8 to 15 character string with at least one upper case letter, one lower case letter, and one digit:
((?=.\d)(?=.[a-z])(?=.*[A-Z]).{8,15})
/(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)/
(\w+@[a-zA-Z_]+?.[a-zA-Z]{2,6})
(\<(/?[^>]+)>)
/^<([a-z1-6]+)([^<]+)*(?:>(.*)<\/\1>| *\/>)$/
/^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
(\d{1,2}\/\d{1,2}\/\d{4})
Will match dates with dashes, slashes or with spaces and optional time separated by a space or a dash:
dd - mm - yyyy, dd / mm / yyyy, dd mm yyyy, dd - mm - yyyy - hh: mm: ss
or dd / mm / yyyy hh: mm: ss
/^(0?[1-9]|[12][0-9]|3[01])([ \/\-])(0?[1-9]|1[012])\2([0-9][0-9][0-9][0-9])(([ -])([0-1]?[0-9]|2[0-3]):[0-5]?[0-9]:[0-5]?[0-9])?$/
/^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]|(?:Jan|Mar|May|Jul|Aug|Oct|Dec)))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2]|(?:Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)(?:0?2|(?:Feb))\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9]|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep))|(?:1[0-2]|(?:Oct|Nov|Dec)))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/