decorative banner

Previous | Next               Table Of Contents > 2 Working with string and numeric variables > 2.6 Comparing strings

2.6 Comparing strings


Strings can be directly compared using the string comparison operators. Additionally, strings can also be matched using wildcards such as *, and ?. This is known as wildcard matching or pattern matching. * matches 0 or more characters while ? matches exactly one character.

Some examples are

if "index.txt" eq ~my_var begin

end



if "*.txt" eq ~my_var begin

end

       

The ftpwildcardmatch command can be used to perform wildcard matching. Additionally, this command allows case insensitive pattern matching when i is passed as a match option. If the strings match, the predefined flag ftpresult is set to the predefined constant success.

The syntax is

ftpwildcardmatch <string to match>, <wildcard pattern string>, <match options>;

Some examples are

ftpwildcardmatch ~my_var, "*.txt", "i"; #case insensitive wildcard match
if success eq ftpresult begin

end

       

The ftpregexmatch command can be used to perform matching using regular expressions similar to that used in Perl. This command allows case insensitive regular expression matching when i is passed as a match option. If the strings match, the predefined flag ftpresult is set to the predefined constant success. Note that for the regular expression pattern string, a \ character must be preceeded by another \.

The syntax is

ftpregexmatch <string to match>, <regex pattern string>, <match options>;

Some examples are

ftpregexmatch ~my_var, "[a-zA-Z0-9]+\\.log", ""; #case sensitive regex match
if success eq ftpresult begin

end


Previous | Next