2.2

PrintShop Web Administrator Guide | 131
Introduction to Regular Expressions
This chapter is an introduction to regular expressions, explaining basic regular expression syntax.
Regular expressions for user input fields use the perl regular expression notation. Note that the user
input regular expressions must match all of the input.
Additional information can be found at the following web sites:
http://regexlib.com
http://www.regular-expressions.info
http://en.wikipedia/wiki/Regular_expression
Syntax
The following sections describe the basic regular expression syntax.
Character selection
Regular expressions can contain both special and ordinary characters. Most ordinary characters,
like "A", "a", or "0", are the simplest regular expressions; they simply match themselves. You can
concatenate ordinary characters, so last matches the string 'last'.
[] Matches a single character that is contained within the brackets. For example, [abc] matches "a",
"b", or "c". [a-z] matches any lowercase letter. These can be mixed: [abcq-z] matches a, b, c, q, r,
s, t, u, v, w, x, y, z, and so does [a-cq-z]. The '-' character should be literal only if it is the last or the
first character within the brackets: [abc-] or [-abc]. To match an '[' or ']' character, the easiest way is
to make sure the closing bracket is first in the enclosing square brackets: [][ab] matches ']', '[', 'a' or
'b'.
[^ ] Matches a single character that is not contained within the brackets. For example, [^abc]
matches any character other than "a", "b", or "c". [^a-z] matches any single character that is not a
lowercase letter. As above, these can be mixed.
( ) Defines a "subexpression".
. Matches any single character. Within [ ] this character has its normal (literal) meaning. For
example, "a.cd" matches "abcd", "a..d" matches "abcd" but [a.cd] matches "a" or "." or "c" or "d".
\d Any digit 0-9
\D Any non-digit
\s Any whitespace character (this is equivalent to the set [ \t\n\r\f\v])
\S Any single non-whitespace
\w Any letter, number or underscore (this is equivalent to the set [a-zA-Z0-9_])
\W Any char except letter, number or underscore
\t ASCII Horizontal Tab (TAB)
\n ASCII Linefeed (LF)
\r ASCII Carriage Return (CR)
\f ASCII Formfeed (FF)
\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 different patterns, but they both describe the set containing gray and grey.