20.5. Advanced matching

[<<<] [>>>]

Up to now we were talking about wild card characters and the joker character defining what matches what as final rule carved into stone. But these rules are only the default behavior of these characters and the program can alter the set of characters that a joker or wild card character matches.

There are 13 characters that can play joker or wild card character role in pattern matching. These are:

* # $ @ ? & % ! + / | < >

When the program starts only the first five characters have special meaning the others are normal characters. To change the role of a character the program has to execute a SET JOKER or SET WILD command. The syntax of the commands are:

SET JOKER expression TO expression
SET WILD expression TO expression

Both expressions should evaluate to string. The first character of the first string should be the joker or wild card character and the second string should contain all the characters that the joker or wild card character matches. The command SET JOKER alters the behavior of the character to be a joker character matching a single character in the compared string. The command SET WILD alters the behavior of the character to be a wild card character matching one or more characters in the compared string. For example if you may want the & character to match one or more of all hexadecimal characters the program has to execute:

SET WILD "&" TO "0123456789abcdefABCDEF"

If a character is currently a joker of wild card character you can alter it to be a normal character issuing one of the commands

SET NO JOKER expression
SET NO WILD expression

where expression should evaluate to a string and the first character of the string should give the character to alter the behavior of.

The two commands are identical, you may always use one or the other; you can use SET NO JOKER for a character being currently wild card character and vice versa. You can execute the command even if the character is currently a normal character in the pattern matching game.

Using the commands now we can see that

Const nl="\n"
Set no wild "*"
a="13*52" like "#*#"
print joker(1)," ",joker(2),nl 

will print

13 52

giving the desired result.

If the expression supposed to result the character for which the role and character set is defined is none of the 13 characters listed above an error occurs.


[<<<] [>>>]