7.1

Table Of Contents
l \D Any non-digit
l \s Any whitespace character (this is equivalent to the set [ \t\n\r\f\v])
l \S Any single non-whitespace
l \w Any letter, number or underscore (this is equivalent to the set [a-zA-Z0-9_])
l \W Any char except letter, number or underscore
l \t ASCII Horizontal Tab (TAB)
l \n ASCII Linefeed (LF)
l \r ASCII Carriage Return (CR)
l \f ASCII Formfeed (FF)
l \v ASCII Vertical Tab (VT)
Alternation
A vertical bar separates alternatives. For example, "gray|grey" can match "gray" or "grey".
Grouping
Parentheses are used to define the scope and precedence of the operators. For example, "gray|grey" and "gr(a|e)y" are dif-
ferent patterns, but they both describe the set containing gray and grey.
Quantification
A quantifier after a character or group specifies how often that preceding expression is allowed to occur. The most common
quantifiers are ?, *, and +:
l ? The question mark indicates there is zero or one of the preceding element. For example, colou?r" matches both color
and colour.
l * The asterisk indicates there are zero or more of the preceding element. For example, ab*c matches "ac", "abc",
"abbc", "abbbc", and so on.
l + The plus sign indicates that there is one or more of the preceding element. For example, ab+c matches "abc",
"abbc", "abbbc", and so on, but not "ac".
l {n} Exactly n occurrences.
l {n,} At least n occurrences.
l {n,m} Between n and m occurrences.
There are 12 characters with special meanings:
l the opening square bracket [
l the backslash \
l the forward slash /
l the caret ^
l the dollar sign $
l the period or dot .
l the vertical bar or pipe symbol |
l the question mark ?
l the asterisk or star *
l the plus sign +
l the opening round bracket (
l the closing round bracket )
Special characters can be escaped by placing a backslash \ before the special character. A backslash can be matched using \\.
Introduction to Regular Expressions
©2010 Objectif Lune Inc - 192 -