like operator

Use the like operator to compare a string to a regular expression. The regular expressions available with like include wildcard and escape characters. The like operator resembles the LIKE keyword in SQL. For more robust regular expressions, see matches operator. The operator makes the comparison character by character, left to right, and ends when one of the following conditions is met:

Syntax

Syntax diagram for the like operator
string
A STRING variable to compare to a regular expression.
regEx
A regular expression to compare string to. The regular expression can be any literal or variable that is assignment compatible with STRING, except for DBCHAR. (EGL cannot recognize double byte wildcard characters.) For more information, see "Regular expression rules" in this topic.

Regular expression rules

You can include any of the following special characters in a regular expression with the like operator:
%
Acts as a wildcard, matching zero or more characters in the source string.
_ (underscore)
Acts as a wildcard, matching a single character in the source string.
\ (backslash)
Indicates that the next character is to be compared to a single character in the source string. The backslash (\) 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 source string. The escape character usually precedes a percent sign (%), an underscore (_), or another backslash.
When you use the backslash as an escape character (as is the default behavior), a problem arises because EGL uses the same escape character to allow inclusion of a double quotation mark in any text expression. In the context of a regular expression, you must specify two backslashes because the text available at run time is the text that lacks the initial backslash. To avoid this problem, specify another character as the escape character by using the escape keyword, as shown in "Examples" in this topic. Note that you cannot use a double quotation mark (") as an escape character.

Any other character in the regular expression is a literal that is compared to a single character in the source string.

Examples

The following example uses wildcards in a regular expression:
myVar01 = "abcdef";

// evaluates as TRUE 
if (myVar01 like "a_c%")
   ;
end
The following example shows the use of an escape character. Note the use of doubled backslashes:
myVar01 = "ab%def";

// evaluates as true 
if (myVar01 like "ab\\%def")
   ;
end 
The following example uses the escape keyword to make the plus sign the escape character for the regular expression:
myVar01 = "ab%def";

// evaluates as true
if (myVar01 like "ab+%def" escape "+")
   ;
end
The like operator ignores trailing blanks in both operands:
// evaluates as true
if ("hello " like "hello      ")
   ;
end

Feedback