Regex Cheets

Building blocks for making Regular Expressions.

REGEX PATTERNS
\w		alphanumeric character
\w+		alphanumeric string
\W 		NOT alphanumeric character (special character)
		 `! " # $ % & ‘ ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~’
\W+ 		NOT alphanumeric string (special character string)
[x] 	character x
[^x] 	NOT character x
[x-y] 	range [0-9] [a-z] [A-Z]
^ 		blank at beginning of line
$ 		blank at end of line
^$ 		blank line (blank beginning of line followed by blank end of line)
\b 		blank at beginning AND end of alphanumeric string
\B 		NOT \b
\< blank at begin of string
\> 		blank at the end of string

REGEX REPETITION OPERATORS
?		matched at most once (optional)
*		matched  zero  or  more times (have not figured out how to use it)
+		matched one or more times. (same as in {1,})
{n} 	matched exactly n times.
{n,} 	matched n or more times.
{n,m} 	matched at least n times and not more than m times. {min, max}

Example:This regex matches email address
\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}\b

Post a Comment

You must be logged in to post a comment.