Regular Expression
GREP = “Global Regular Expression Print”
Online Regex Editor: regexpal( http://www.regexpal.com/ )
Modes
Standard : /re/
Global : /re/g
Case Insensitive : /re/i
Multiline : /re/m
Dot-matches-all : /re/s
Literals
a matches a
b matches b
like this so on…
Meta-characters
\ . * + — {} [] ^$ | ? () : ! =
Wildcard Meta-Character
/h . t/ matches “hat”, “hot” but not “heat”
/9 . 00/ matches “9.00” but also “9500” or “9–00”
Escaping Meta-Characters
/9 \. 00/ matches “9.00” but not “9500” or “9–00”
Other Special Characters
Spaces
Tab
Line Return (\r,\n,\r\n)
ASCII or ANSI Codes
Character Sets
/gr[ea]y/ matches “gray” & “grey”
/gr[ea]t/ does not matches with “great”
Character Ranges
[0–9]
[A-Za-z]
Negative Characters
^ Negate a character set
[^aeiou] — consonants
see[^mn] matches “seek” and “sees” but not “seem” and “seen”
Meta-characters inside character sets
/h[abc.xyz]t/ matches with “hat” & “h.t” but not to “hot”
Shorthand Characters
\d digit [0–9]
\w word character [0–9A-Za-z_]
\s whitespace [ \t\r\n]
\D not digit [^0–9]
\W not word character [^0–9A-Za-z_]
\S not whitespace [^ \t\r\n]
POSIX Bracket Expression

Repetition Meta Characters
* preceding items zero or more times
+ preceding items one or more times
? preceding items zero or one times
/cats*/ matches “cat”, “cats” , “catsssss”
/cats+/ matches “cats” and “catssss” but not “cat”
/cats?/ matches “cat” and “cats” but not to “catssss”
Quantified Repetition
{min,max}
/d{4,9} matches with word length from 4 to 9
/d{4} matches with word exactly with length 4
/d{4,} marches with length from 4 to infinity
Grouping Meta Characters
/(abc)+/ matches “abc” and “abcabcabc”
/(in)?dependent / matches “dependent” and “independent”
Alternation Meta Character
| match previous or next expression
It is an “OR” operator
Start and End Anchors
^ Start of string line
$ End of string line

Word Boundaries
/b word boundary (start/end )
/B not a word boundary
Back references
\1 through \9
Positive Lookahead Assertions
?=
if lookahead assertion fails that match also fails.
Zero width does not include in any group
Syntax : /(?=regex)/
Negative Lookahead Assertions
Syntax : /(?!regex)/
Look Behind Assertion
/(?<=regex)/
/(?<!regex)/