beautypg.com

Regular expressions, Simple regular expressions, Bracket expressions – Visara Master Console Center Scripting Guide User Manual

Page 54: Simple regular expressions bracket expressions

background image

Chapter 4 Regular Expressions

Scripting Guide

54

Regular Expressions

Regular expressions (REs) or patterns are textual statements including
specialized characters to control the search. REs provide a powerful way
to search strings by specifying patterns. Matched search patterns also
called substrings or a sequence (of characters).
Simple REs match a single character. More complex REs are built by
concatenating simpler REs. Complex REs are classified as those that
match a single character and those that match multiple characters. REs
are defined recursively. For example, if you concatenate two REs, the
resultant string is one RE.
A variety of utilities and languages use REs. This results in different
syntax rules for REs. The MCC follows the Extended Regular Expression
rules for Unix.
Important notes on the definition of regular expressions in this guide:

ƒ

The term “regular expression” in this guide includes extended regular
expression rules.

ƒ

The terms “pattern” and “regular expression” can be used
interchangeably.

ƒ

The term “match” describes a substring in a string that is successfully
specified by a pattern or RE.

Simple Regular Expressions

Some Expression

This is a simple regular expression. It will match any text containing
"Some Expression". There are no special characters contained in this
example.

Bracket Expressions

Some[0-9]Expression

This expression searches for "Some" and "Expression" separated by a
numeric character. Thus, "Some0Expression" and "Some6Expression"
both match.
The brackets ‘[ ]’ searches "match any character contained within" and is
referred to as a bracket expression. Lists of characters may be specified
within brackets, as well as character ranges. For instance:
[A-Za-z] Matches any alphabetic character.
[ABC]

Matches A, B, or C.

If the first character after the open bracket is a circumflex (^), the
expression is reversed — the expression matches any character NOT in
the brackets. Note that most of the other special characters are not
special inside brackets, as in: