beautypg.com

Special characters in regular expressions – Visara Master Console Center Scripting Guide User Manual

Page 64

background image

Chapter 4 Regular Expressions

Scripting Guide

64

Special Characters in Regular Expressions

Table 12. Regular Expressions, Special Characters describes the various
special characters that may be used in regular expressions. The
characters are special — except in bracket expressions or following a
backslash.

Character Description

.

A period matches any single character.

\

When placed before a special character, a backslash nullifies

that special character. This allows searches for a character

that would otherwise be special (such as a period).

^

A circumflex matches the beginning of the line. The

circumflex is special when used as an anchor or as the first
character of a bracket expression.

$

A dollar sign matches the end of the line.

[ ]

Brackets match any single instance of the characters inside

the brackets. Ranges can be specified, for instance, A-F. If
the first character after the open bracket is a circumflex, the

search is negated—matches any character not in the list. For
example, G-Z if you specified A-F. If a dash is to be matched

as a regular character, make it the first or last character in

the list.
It is not valid to use a left brace that is not part of an interval

expression (of course, quoting with a backslash removes such

invalidity).

( )

Parentheses form a subexpression. Up to nine

subexpressions are allowed in a regular expression; they may
be nested.
Outside a bracket expression, do not use a left parenthesis

unless it is preceded with a backslash and quoted “\(”.
To search for the string “()”, use the quoted form by preceding

with a backslash “\()”.

*

1

An asterisk matches zero or more occurrences of the

previous character, bracket, or subexpression—depending on
what precedes the asterisk.

+

1

A plus sign matches one or more occurrences of the previous

character, bracket, or subexpression—depending on what

precedes the plus sign.

?

1

A question mark matches exactly zero or one occurrences of

the previous character, bracket, or subexpression—depending

on what precedes the question mark.

{n}

1

Brackets match exactly n occurrences of the previous

character, bracket, or subexpression—depending on what
precedes the {n}.

{n,m}

{n,} matches n or more. {,m} matches m or less. {n,m} matches
n to m occurrences. Replace n and m with numbers specifying