The operator LIKE

[<<<] [>>>]

Pattern matching in ScriptBasic is similar to the pattern matching that you get used to on the UNIX or Windows NT command line. The operator LIKE compares a string to a pattern.

string LIKE pattern

Both string and pattern are expressions that should evaluate to a string. If the pattern matches the string the result of the operator is TRUE, otherwise the result is FALSE.

The pattern may contain normal characters, wild card characters and joker characters. The normal characters match themselves. The wild card characters match one or more characters from the set they are for. The joker characters match one character from the set they stand for. For example:

"file.txt" like "*.txt" is TRUE
"file0.txt" like "*?.txt" is TRUE
"file.text" like "*.txt" is FALSE

The wild card character * matches a list of characters of any code. The joker character ? matches a single character of any code. In the first print statement the * character matches the sub-string file and .txt matches .txt at the end of the string. In the second example * matches the string file and the joker ? matches the character 0. The wild card character * is the most general wild card character because it matches one or more of any character. There are other wild card characters. The character # matches one or more digits, $ matches one or more alphanumeric characters and finally @ matches one or more alpha characters (letters).

A space in the pattern matches one or more white spaces, but the space is not a regular wild card character, because it behaves a bit different.

Note that wild card character match ONE or more characters and not zero or more as in other systems. Joker characters match exactly one character, and there is only one joker character by default: the character ?, which matches a single character of any code.


[<<<] [>>>]