beautypg.com

Visara Master Console Center Scripting Guide User Manual

Page 61

background image

Chapter 4 Regular Expressions

Scripting Guide

61

Matching Multiple Characters in Bracket Expressions

The following rules are used to build multiple character-matching REs
from bracket expressions (single character-matching REs).

ƒ

A concatenation of REs matches the concatenation of the strings
matched by each component of the RE.

ƒ

A subexpression can be defined within an RE by enclosing it between
parentheses “( )”. Such subexpressions match whatever would have
been matched without the parentheses.

ƒ

A concatenation of REs enclosed in parentheses matches whatever the
concatenation without the parentheses matches. For example, both
REs “ab” and “(ab)” match the second and third characters of the
string “cabcdabc”.

ƒ

An RE matching a single character or an RE enclosed in parentheses
followed by the special character plus sign “+” matches what one or
more consecutive occurrences of the RE would match. For example,
the RE “(ab)a+” matches the second to sixth characters in the string
“cabaaabc” and “c(ab)+” matches the first to seventh characters in the
string “cabababc”.

ƒ

An RE matching a single character or an RE enclosed in parentheses
followed by the special character asterisk “*” matches what zero or
more consecutive occurrences of the RE would match. For example,
the RE “b*c” matches the first character in the string “cabbbcde”, and
the RE “c*de” matches the second to sixth characters in the string
“dcccdec”. The REs “[cd]+” and “[cd][cd]*” are equivalent and “[cd]*”
and “[cd][cd]” are equivalent when matching the string “cd”.

ƒ

An RE matching a single character or an RE enclosed in parentheses
followed by the special character question mark “?” matches what zero
or one consecutive occurrence of the RE would match. For example,
the RE “c?d” matches the third character in the string “abdbcccde”.

ƒ

An RE matching a single character or an RE enclosed in parentheses,
followed by an interval expression of the format “{i}”, “{i,}”, or “{i,j}”,
matches what repeated consecutive occurrences of the RE would
match. Such an RE followed by:

-

{i} matches exactly i occurrences of the character matched by the RE

-

{i,} matches at least i occurrences of the character matched by the RE

-

{i,j} matches any number of occurrences of the character matched by the RE from
i to j inclusive.

The values of i and j must be integers in the range 0 <= i <= j <= 255.
Whenever a choice exists, the pattern matches as many occurrences as
possible. Note that if i is zero, the interval expression is equivalent to
the null RE.

For example, the RE “d{3}” matches characters eight through ten in the
string “abcbcbcddddde” and the RE “(bc){2,}” matches characters two to
seven in the same string.