This example demonstrates how to use surrounding
text to identify a string to be replaced without also
replacing the surrounding text.
The following filter replaces the month part of
a date with the string "mmm". For example, the
string "14-OCT-1999" will be replaced by the string
"14-mmm-1999":
day := any(" 123") + digit;
month := "JAN" | "FEB" | "MAR" | "APR" |
"MAY" | "JUN" | "JUL" | "AUG" |
"SEP" | "OCT" | "NOV" | "DEC";
year := any(digits,4);
date := (day + "-"@day_part) + month + ("-" + year@year_part);
global_replace( date, 'str(day_part) + "mmm" + str(year_part)',,ON);
The day part of the date and the "-" character are
assigned to the partial pattern variable day_part and
the year part of the date and preceding "-" assigned
to year_part. These partial pattern variables are then
included in the replacement string.
When partial pattern variable are used in the
replacement string they must be evaluated for
each replacement. To do this, set the parameter
evaluate_replacement to ON, as shown above.
When the replacement string is to be evaluated, string
literals must be nested inside further quotes. This
is most easily done by using single quotes for the
outer string and double quotes for any nested string
literals, or vice-versa. Also, any partial pattern
variables must be converted to strings using the DECTPU
procedure STR.
Note that including LINE_END in the definition of a
partial pattern variable does not have the effect
of retaining the line break. See example 6 for a
resolution of this problem.