beautypg.com

3 using pattern operators – Compaq DEC Text Processing Utility AA-PWCBD-TE User Manual

Page 53

background image

DEC Text Processing Utility Data Types

3.7 Pattern Data Type

3.7.3 Using Pattern Operators

The following are the DECTPU pattern operators:

Concatenation operator ( + )

Link operator ( & )

Alternation operator ( | )

Partial pattern assignment operator ( @ )

The pattern operators are equal in DECTPU’s precedence of operators. For
more information on the precedence of DECTPU operators, see Chapter 4.
Pattern operators associate from left to right. Thus, the following two DECTPU
statements are identical:

pat1 := a + b & c | d @ e;
pat1 := (((a + b) & c) | d) @ e;

In addition to the pattern operators, you can use two relational operators, equal
( = ) and not equal (<>), to compare patterns.

The following sections discuss the pattern operators.

3.7.3.1 + (Pattern Concatenation Operator)

The concatenation operator ( + ) tells SEARCH or SEARCH_QUIETLY that text
matching the right pattern element must immediately follow the text matching
the left pattern element in order for the complete pattern to match. In other
words, the concatenation operator specifies a search in which the right pattern
element is anchored to the left. For example, the following pattern matches only
if there is a line in the searched text that ends with the string abc.

pat1 := "abc" + line_end;

If SEARCH or SEARCH_QUIETLY finds such a line, the built-in returns a range
that contains the text abc and the end of the line.

Compaq recommends that you use the concatenation operator rather than the
link operator unless you specifically require the link operator.

3.7.3.2 & (Pattern Linking Operator)

The link operator ( & ) is similar to the concatenation operator ( + ). Unlike the
concatenation operator, the link operator does not necessarily cause an anchored
search. If you define a pattern by specifying any pattern element, an ampersand
( & ), and a pattern or keyword variable, a search for each subpattern is not an
anchored search.

If you link elements other than pattern variables, the search is an anchored
search unless you specify otherwise. Strings, constants, and the results of built-in
procedures are not pattern variables.

For example, suppose you defined two subpattern variables as follows:

p1 := "a" & ANY("012345678");
p2 := "c" & ARB (1);

You then define the following pattern variable:

pat_var := p1 & p2

DEC Text Processing Utility Data Types 3–13