Compaq AA-PWCBD-TE Computer Accessories User Manual


 
DEC Text Processing Utility Data Types
3.7 Pattern Data Type
3.7.6 Anchoring a Pattern
Anchoring a pattern forces SEARCH or SEARCH_QUIETLY to match the
anchored part of the pattern to text starting at the current search position. If
the anchored part of a pattern fails to match that text, SEARCH or SEARCH_
QUIETLY stops searching.
Usually, all pattern elements other than the first pattern element of a pattern
are anchored. This means that a pattern can match text starting at any point in
the searched text but that once it starts matching, each pattern element must
match the text immediately following the text that matched the previous pattern
element.
To direct DECTPU to stop searching if the characters starting at the editing point
do not match the pattern, use the ANCHOR keyword as the first pattern element.
For example, the following pattern matches only if the string abc occurs at the
editing point:
pat1 := ANCHOR + "abc";
There are two ways to unanchor pattern elements in the midst of a pattern. The
easiest is to concatenate or link the UNANCHOR keyword before the pattern
element you want to unanchor. The following pattern unanchors the pattern
element xyz:
pat1 := "abc" + UNANCHOR + "xyz";
This means that the pattern pat1 matches any text beginning with the characters
abc and ending with the characters xyz. It does not matter what or how many
characters or line breaks appear between the two sets of characters. Since
SEARCH or SEARCH_QUIETLY matches the first xyz it finds, the text between
the two sets of characters by definition does not contain the string xyz.
The second way to unanchor a pattern element is to use the special properties of
the link operator ( & ). While the concatenation operator always anchors the right
pattern element to the left, the link operator does so only if the right pattern
element is not a pattern variable. If the link operator’s right pattern element is a
pattern variable, the link operator unanchors that pattern element. The pattern
pat2 defined by the following assignments matches any sequence of text that
begins with the letter a and ends with a digit.
pat1 := ANY ("0123456789");
pat2 := "a" & pat1;
Any amount of text can occur between the a and the digit. Pat2 matches the
same text as the following pattern:
pat3 := "a" + UNANCHOR + ANY( "0123456789" );
The link operator unanchors a pattern variable regardless of what the left pattern
element is. In particular, the following two patterns match the same text:
pat2 := "a" & pat1;
pat3 := "a" & ANCHOR & pat1;
If you are using pattern variables to form patterns and you wish those variables
to be anchored, you have two choices: you can use the concatenation operator, or
you can use the ANCHOR keyword as the first element of any pattern the pattern
variables reference.
DEC Text Processing Utility Data Types 3–17