matches operator

In a logical expression, you can compare a string expression against another string (called a match criterion), character position by character position from left to right. Use of this feature is similar to use of regular expressions in UNIX or Perl.

An example is as follows:

  // variable myVar01 is the string expression 
  // whose contents will be compared to a match criterion
  myVar01 = "abcdef";

  // the next logical expression evaluates to "true" 
  if (myVar01 matches "a?c*")
    ;
  end

The match criterion can be either a literal or item of type CHAR or MBCHAR; or an item of type UNICODE. You can include any of these characters in the match criterion:

*

Acts as a wild card, matching zero or more of any characters in the string expression

?

Acts as a wild card, matching a single character in the string expression

[ ]

Acts as a delimiter such that any one of the characters between the two brackets is valid as a match for the next character in the string expression. The following component of a match criterion, for example, indicates that a, b, or c is valid as a match:
  [abc]

-

Creates a range within the bracket delimiters, such that any character within the range is valid as a match for the next character in the string expression. The following component of a match criterion, for example, indicates that a, b, or c is valid as a match:
  [a-c]

The hyphen (-) has no special meaning outside of bracket delimiters.

^

Creates a wild-card rule such that, if the caret (^) is the first character inside bracket delimiters, any character other than the delimited characters is valid as a match for the next character in the string expression. The following component of a match criterion, for example, indicates that any character other than a, b, or c is valid as a match:
  [^abc]

The caret has no special meaning in these cases:

  • It is outside of bracket delimiters

  • It is inside of bracket delimiters, but not in the first position

\

Indicates that the next character is to be compared to a single character in the string expression. The backward virgule (\) is called an escape character because it causes an escape from the usual processing; the escape character is not compared to any character in the string expression.

The escape character usually precedes a character that is otherwise meaningful in the match criterion; for example, an asterisk (*) or a question mark (?).

When you use the backward virgule as an escape character (as is the default behavior), a problem arises because EGL uses the same escape character to allow inclusion of a quote mark in any text expression. In the context of a match criterion, specify two backward virgules because the text available at run time is the text that lacks the initial virgule.

It is recommended that you avoid this problem. Specify another character as the escape character by using the escape clause, as shown in a later example. However, you cannot use a double quote mark (") as an escape character.

Any other character in matchCriterion is a literal that is compared to a single character in string expression.

The following example shows use of an escape clause:

  // variable myVar01 is the string expression 
  // whose contents will be compared to a match criterion
  myVar01 = "ab*def";

  // the next logical expression evaluates to "true" 
  if (myVar01 matches "ab\\*[abcd][abcde][^a-e]")
    ;
  end

  // the next logical expression evaluates to "true"
  if (myVar01 matches "ab+*def" escape "+")
    ;
  end

Related reference
EGL statements
Logical expressions
Text expressions