Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Regular Expressions List
//Regular Expressions List
//Short Tutorial
\ // the escape character - used to find an instance of a metacharacter like a period, brackets, etc.
. // match any character except newline
x // match any instance of x
^x // match any character except x
[x] // match any instance of x in the bracketed range - [abxyz] will match any instance of a, b, x, y, or z
| // an OR operator - [x|y] will match an instance of x or y
() // used to group sequences of characters or matches
{} // used to define numeric quantifiers
{x} // match must occur exactly x times
{x,} // match must occur at least x times
{x,y} // match must occur at least x times, but no more than y times
? // preceding match is optional or one only, same as {0,1}
* // find 0 or more of preceding match, same as {0,}
+ // find 1 or more of preceding match, same as {1,}
^ // match the beginning of the line
$ // match the end of a line
[:alpha:] // Represents an alphabetic character. Use [:alpha:]+ to find one of them.
[:digit:] // Represents a decimal digit. Use [:digit:]+ to find one of them.
[:alnum:] // Represents an alphanumeric character ([:alpha:] and [:digit:]).
[:space:] // Represents a space character (but not other whitespace characters).
[:print:] // Represents a printable character.
[:cntrl:] // Represents a nonprinting character.
[:lower:] // Represents a lowercase character if Match case is selected in Options.
[:upper:] // Represents an uppercase character if Match case is selected in Options.
\d // matches a digit, same as [0-9]
\D // matches a non-digit, same as [^0-9]
\s // matches a whitespace character (space, tab, newline, etc.)
\S // matches a non-whitespace character
\w // matches a word character
\W // matches a non-word character
\b // matches a word-boundary (NOTE: within a class, matches a backspace)
\B // matches a non-wordboundary
// http://regexlib.com
// http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/
// Email address
^[\\w\\-]+(\\.[\\w\\-]+)*@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$
^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$
^([\w\.*\-*]+@([\w]\.*\-*)+[a-zA-Z]{2,9}(\s*;\s*[\w\.*\-*]+@([\w]\.*\-*)+[a-zA-Z]{2,9})*)$ //List of semi-colon seperated email addresses
^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$
// IP Address
^((?:(?: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]?))*$
// Credit Cards
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$
// Username of type test@test
[^@/]+@[^@/]+
// Multiple spaces replacement
\\s+
// Non-alphanumeric replacement
[^a-zA-Z0-9]
// Blank line
^$
// Positive integers
^[1-9]+[0-9]*$
// Positive decimal values
(^\d*\.?\d*[0-9]+\d*$)|(^[0-9]+\d*\.\d*$)
// Percentage (2 decimal places)
^-?[0-9]{0,2}(\.[0-9]{1,2})?$|^-?(100)(\.[0]{1,2})?$
// State abbreviation
[A-Z][A-Z] //you may choose to put spaces either before or after the regex.
// Phone Numbers
(^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)
// City, State abbreviation
.*, [A-Z][A-Z]
// Zip Code
[0-9]\{5\}(-[0-9]\{4\})? //84094 or 84094-1234
// Social security number, such as: ###-##-####
[0-9]\{3\}-[0-9]\{2\}-[0-9]\{4\}
// Dollar amounts, specified with a leading $ symbol
\$[0-9]*.[0-9][0-9]
// DATE
[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} //2003-08-06
[A-Z][a-z][a-z] [0-9][0-9]*, [0-9]\{4\} //Jan 3, 2003
^(\d{1,2})\/(\d{1,2})\/(\d{2}|(19|20)\d{2})$ //DD/MM/YY or DD/MM/YYYY or MM/DD/YY or MM/DD/YYYY
// HTML Tags except <p> </p>
<(?>/?)(?!p).+?>
// Font Tags Replacement
<(FONT|font)([ ]([a-zA-Z]+)=("|')[^"\']+("|'))*[^>]+>([^<]+)(</FONT>|</font>
// URL
^http(s)?:\/\/((\d+\.\d+\.\d+\.\d+)|(([\w-]+\.)+([a-z,A-Z][\w-]*)))(:[1-9][0-9]*)?(\/([\w-.\/:%+@&=]+[\w- .\/?:%+@&=]*)?)?(#(.*))?$/i
// NOTEPAD ++ Replace
// Insert a span in anchor
Find : (<a.*>)(.*)</a>
Replace : \1<span class="icon3 pdf">\2</span></a>
@kayode-adechinan

This comment has been minimized.

Copy link

@kayode-adechinan kayode-adechinan commented May 8, 2018

Waoh fantastic! God bless you

@erikfenriz

This comment has been minimized.

Copy link

@erikfenriz erikfenriz commented May 19, 2018

Nicely done. Ty

@rodrigoramirez93

This comment has been minimized.

Copy link

@rodrigoramirez93 rodrigoramirez93 commented May 23, 2018

Great! Thank you!

@juanpablocs

This comment has been minimized.

Copy link

@juanpablocs juanpablocs commented Jan 6, 2020

these are missing:

\r
\n
@muzammilsiddiq

This comment has been minimized.

Copy link

@muzammilsiddiq muzammilsiddiq commented Jun 29, 2021

Kindly add a regular expression for strong, medium, and weak passwords.

@TranQuocToan1996

This comment has been minimized.

Copy link

@TranQuocToan1996 TranQuocToan1996 commented Aug 2, 2021

wow thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment