|
blondi Beginner
Joined: 06 Apr 2003 Posts: 15
|
Posted: Wed Apr 09, 2003 10:01 pm
#if =~ pattern syntax |
I know the thing is in the helpfiles, but this piece of englisch is to hard for me to understand cause englisch is not my main language
So please could somebody tell me (with examples) how to use patterns in the IF statement and how to refer and get the contens of the pattern parameters
Thanxs |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Wed Apr 09, 2003 11:42 pm |
The =~ operator performs a comparison between its two operands. What's special about this operator is that it performs the comparison just as if the first operand is a line received from the MUD and the second operand is a pattern. In this case, it will evaluate to true if the first operand matches the pattern (the second operand) and false otherwise. The pattern that you use may also contain parts of it enclosed in parenthesis so that you may access what was matched by the pattern in that particular position. You access the saved portions with %%1..%%n. Examples:
#IF ("some big red cars" =~ "* {blue|yellow|red|green} %w") {#SH The pattern matches.}
#IF ("some big white cars" =~ "* {blue|yellow|red|green} %w") {#SH The pattern matches.}
Only the first of these will produce the message of "The pattern matches." Another example:
#IF ("some big blue cars" =~ "* ({blue|yellow|red|green}) %w") {#SH The pattern matches and the color matched was %%1.}
This one will output the message "The pattern matches and the color matched was blue."
Kjata |
|
|
|
blondi Beginner
Joined: 06 Apr 2003 Posts: 15
|
Posted: Thu Apr 10, 2003 9:58 am |
Thank you very much.
Now it is clear to me, what is ment with the double %% |
|
|
|
Emit Magician
Joined: 24 Feb 2001 Posts: 342 Location: USA
|
Posted: Sat Apr 12, 2003 4:49 pm |
Ah, if you use that last if statement inside an alias:
#alias check {
#IF ("some big blue cars" =~ "* ({blue|yellow|red|green}) %w") {#SH The pattern matches and the color matched was %%1.}
#SH The argument to check was %1
}
then you need to use %%1 to refer to the paramater from the if check, because %1 is the first argument to the alias. Same with triggers.
check expand
would produce:
The pattern matches and the color matched was blue.
The argument to check was expand
--------
salford.cslab.uky.edu:4000 |
|
|
|
|
|