Quick Reference to Regex

[ ] –> Brackets. They enclose a list of characters that represent a single character in the expression.

Inside the brackets, one can specify:

-   –> For Ranges

^   –> For negation

.   –>   Period. Matches a single character

() –>   Parenthesis. Used to enclose an expression

| –>    Or

Positions:

^ Marks the beggining of the line

$ Marks the end of the line

/< Marks the beggining of a word

/> Marks the end of a word

Repetition Operators:

OperatorDescription
?Optional and matched at most once
*Zero or more times
+One or more times
{n}n times.
{n,}n or more times.
{n,m}At least n times, but not more than m times

Examples:

t[a-z]xmatchestux
doesn’t matchtUx
[^w]inmatcheslin
doesn’t matchwin
 t.xmatches tux
doesn’t matchtuux
(t.x|m.x)matches tux, mux 
 ^t.xmatchestux rules 
doesn’t matchrules tux 
tu{2}xmatchestuux 
doesn’t matchtux
^.{2,15}$Between 2 and 15 characters
^[0-9]Starts with a number
[^[:alnum:]]Contains special characters