Elnur21 / regex

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regular expression syntax cheatsheet

Regular Expression Syntax Cheat Sheet
Element Short Description
\ Forces special characters to be treated as ordinary characters
^ Indicates the beginning of the pattern (i.e., forces checking from the first character)
$ Indicates the end of the pattern (i.e., forces checking until the last character)
* Used when the preceding character or group may occur zero or more times
+ Used when the preceding character or group may occur one or more times
? Used when the preceding character or group may occur zero or one time
. Represents any single character
[abc] Represents any single character within the brackets
[^abc] Represents any single character not within the brackets
[a-z] Represents any single character within the specified range
[^a-z] Represents any single character not within the specified range
x|y Represents either "x" or "y"
(pattern) Represents a group
(?<name>pattern) Creates a named group
{n} Represents when the preceding character or group occurs exactly "n" times
{n,} Represents when the preceding character or group occurs "n" or more times
{n,m} Represents when the preceding character or group occurs at least "n" and at most "m" times
(?=…) Positive lookahead (requires a specific character or text to be present in the search context)
(?!…) Negative lookahead (requires a specific character or text to be absent in the search context)
(?<!-)\d Negative lookahead (Represents a digit not preceded by a negative sign)
(?<=-)\d Positive lookahead (Represents a digit preceded by a negative sign)
\b Represents the boundary between a word character and a non-word character
\B Represents a position that is not a word boundary
\d Represents a digit
\D Represents a non-digit character
\n or \r\n Represents a new line
\s Represents a whitespace character
\S Represents a non-whitespace character
\t Represents a tab
\w Represents a word character, including "_" but excluding other symbols
\W Represents a non-word character, excluding "_" but including other symbols

Top 5 Regular Expressions

Email
^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
Web Address
^(http(s):\/\/.)[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$
Phone Number
^(\+994|0)(50|51|55|70|77|99|10)-(\d{3}-\d{2}-\d{2})$
Name
^[A-ZƏ]{1}[a-zə]{2,}$
Password
^((?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#])).{8,}$

About