Skip to content

Instantly share code, notes, and snippets.

Created June 26, 2012 23:56
Star You must be signed in to star a gist
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
// Email address
^([\w\.*\-*]+@([\w]\.*\-*)+[a-zA-Z]{2,9}(\s*;\s*[\w\.*\-*]+@([\w]\.*\-*)+[a-zA-Z]{2,9})*)$ //List of semi-colon seperated email addresses
// IP Address
// Credit Cards
// Username of type test@test
// Multiple spaces replacement
// Non-alphanumeric replacement
// Blank line
// Positive integers
// Positive decimal values
// Percentage (2 decimal places)
// State abbreviation
[A-Z][A-Z] //you may choose to put spaces either before or after the regex.
// Phone Numbers
// City, State abbreviation
.*, [A-Z][A-Z]
// Zip Code
[0-9]\{5\}(-[0-9]\{4\})? //84094 or 84094-1234
// Social security number, such as: ###-##-####
// Dollar amounts, specified with a leading $ symbol
[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>
// 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>
Copy link

Waoh fantastic! God bless you

Copy link

Nicely done. Ty

Copy link

Great! Thank you!

Copy link

these are missing:


Copy link

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

Copy link

wow thank you so much.

Copy link

ghost commented Sep 24, 2021

It is very useful for me. Thanks

Copy link

Copy link


Copy link

great job, thank u VERY much!

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