Unknown2006-08-01 10:13:46
Hi, I'd like to know a bit more about wildcards, what are their functions and how to use them. And also if you give an example of each, I'd appreciate it well
The ones that are commonly used so far in Ethelon's Free System is: *, /, $, \\, n, ?, ., ^, etc. Thanks!!!!
The ones that are commonly used so far in Ethelon's Free System is: *, /, $, \\, n, ?, ., ^, etc. Thanks!!!!
Unknown2006-08-01 12:44:08
I'd recommend checking out help files for clients that use wildcards as they will explain them in more detail than most of us will. You could also search out a good regular expressions tutorial and read up on those wildcards.
Unknown2006-08-01 13:17:51
When you're making a trigger or alias, you have a checkbox called "Regular Expression". If you don't check it, the only wildcard you get is *, and it'll match on anything (letters, whitespace, digits, punctuation) and store what it's matched as a variable. So, say you make a trigger with the pattern "the*dog". Here's what it matches on (and what it stores in brackets): "thedog" (nothing), "the dog" (" "), "the green dog" (" green "), "the happy, fuzzy green dog" (" happy, fuzzy green "), "the %*^(&&@# dog" ("%*^(&&@#"). And that's it.
Say you check "Regular Expression." Regexes are a syntax for matching text patterns, common in many text editors and scripting languages. They can be pretty tough to grasp, but you only need some basics. ^ matches on the start of a line. (It also does something more complicated, but chances are you won't ever do it by accident.) $ matches on the end of a line. . matches on any character. \\ is an escape character, indicating that the character that follows is "special". So what can follow? Well, you can put \\ before a period or backslash or other funny character, to indicate that they're not special characters. Or, you can use the following special characters: n, for newline (I'm not entirely sure how this differs from using ^ and $), d, for digit, w, for word (letters and digits, but not whitespace or special characters), s, for whitespace, or you can designate your own set in square brackets: for example, means that you'll match on one of those four characters. By themselves, any of these notations mean you're looking for a single character of that type. \\w will match one letter or digit, for instance. After this notation, you can also indicate how many of that character you're looking for: * means "zero or more", + means "one or more". So, \\d+ means "match one or more digits".
Unlike the common wildcard above, regexes don't automatically store the thing they matched as a variable. You have to specify that by putting parentheses around the notation. So, \\d matches on one digit, but discards that information, while (\\d) matches on one digit and captures it as a variable.
Examples:
the.*dog matches "thedog", "the furry, happy dog", "the ^(&(_( dog", etc..., but doesn't store what it's matched
the (\\w+) dog matches "the furry dog", "the 3rd dog", but not "the &)*)&)& dog" nor "the furry happy dog", and it stores what it's matched as a variable.
dog matches "dog" wherever it appears on a line. If you check the "repeat on same line" box, it'll match it every time it appears on a line.
^dog matches "dog" only when it appears at the start of a new line.
dog$ matches "dog" only when it appears at the end of a line. (Careful with $, I'm not sure, but I think there's usually a space at the end of lines coming from Lusternia.)
^(\\d+)h\\, (\\d+)m\\, (\\d+)e\\, (\\d+)p.* (*)\\- captures my prompt! Let's dissect it: ^ looks for the start of a line, the (\\d+)'s capture health, mana, ego and power values, the .* matches without storing any other stats I'll configure on (like, if I added endurance and willpower to the prompt), and (*) captures the letters indicating eq, balance and defences.
Another fun thing you can do with regexes: you can supply alternatives with |, meaning "or". For instance: @target stands up and stretches (his|her) arms out wide. (This shows another fun thing: you can include variables in trigger patterns. Just put a @ and the variable name, and be sure to check "Expand variables".) the (|shaggy) dog will match on "the dog" or "the shaggy dog", and only on those. (The alternatives are "shaggy" or nothing.) Or try: Tarox is in the sign of the (Antlers|Lion|Spider|Bumblebee).
Finally, note that you have to use regexes to do multiline triggers. Here's a neat thing for capturing warrior and debating messages, and other lines where you're not sure if you're going to run into a new line or not, nor where the line's going to break off. Check the "Regular Expression" and "Multiline" boxes, then:
can only (|\\n)blink (|\\n)in (|\\n)astonishment (|\\n)at (|\\n)your (|\\n)astounding (|\\n)logic.
Every one of those (|\\n) is a potential line break. There could be a newline there, or there could be nothing. That way, no matter where the newline comes in that message, your trigger will match.
Have a look through the section on Regular Expressions in the MUSHclient help, and experiment lots with the "Test Trigger..." option. The only way you'll get the hang of it is by playing around. Explanations always sound unnecessarily complicated.
Say you check "Regular Expression." Regexes are a syntax for matching text patterns, common in many text editors and scripting languages. They can be pretty tough to grasp, but you only need some basics. ^ matches on the start of a line. (It also does something more complicated, but chances are you won't ever do it by accident.) $ matches on the end of a line. . matches on any character. \\ is an escape character, indicating that the character that follows is "special". So what can follow? Well, you can put \\ before a period or backslash or other funny character, to indicate that they're not special characters. Or, you can use the following special characters: n, for newline (I'm not entirely sure how this differs from using ^ and $), d, for digit, w, for word (letters and digits, but not whitespace or special characters), s, for whitespace, or you can designate your own set in square brackets: for example, means that you'll match on one of those four characters. By themselves, any of these notations mean you're looking for a single character of that type. \\w will match one letter or digit, for instance. After this notation, you can also indicate how many of that character you're looking for: * means "zero or more", + means "one or more". So, \\d+ means "match one or more digits".
Unlike the common wildcard above, regexes don't automatically store the thing they matched as a variable. You have to specify that by putting parentheses around the notation. So, \\d matches on one digit, but discards that information, while (\\d) matches on one digit and captures it as a variable.
Examples:
the.*dog matches "thedog", "the furry, happy dog", "the ^(&(_( dog", etc..., but doesn't store what it's matched
the (\\w+) dog matches "the furry dog", "the 3rd dog", but not "the &)*)&)& dog" nor "the furry happy dog", and it stores what it's matched as a variable.
dog matches "dog" wherever it appears on a line. If you check the "repeat on same line" box, it'll match it every time it appears on a line.
^dog matches "dog" only when it appears at the start of a new line.
dog$ matches "dog" only when it appears at the end of a line. (Careful with $, I'm not sure, but I think there's usually a space at the end of lines coming from Lusternia.)
^(\\d+)h\\, (\\d+)m\\, (\\d+)e\\, (\\d+)p.* (*)\\- captures my prompt! Let's dissect it: ^ looks for the start of a line, the (\\d+)'s capture health, mana, ego and power values, the .* matches without storing any other stats I'll configure on (like, if I added endurance and willpower to the prompt), and (*) captures the letters indicating eq, balance and defences.
Another fun thing you can do with regexes: you can supply alternatives with |, meaning "or". For instance: @target stands up and stretches (his|her) arms out wide. (This shows another fun thing: you can include variables in trigger patterns. Just put a @ and the variable name, and be sure to check "Expand variables".) the (|shaggy) dog will match on "the dog" or "the shaggy dog", and only on those. (The alternatives are "shaggy" or nothing.) Or try: Tarox is in the sign of the (Antlers|Lion|Spider|Bumblebee).
Finally, note that you have to use regexes to do multiline triggers. Here's a neat thing for capturing warrior and debating messages, and other lines where you're not sure if you're going to run into a new line or not, nor where the line's going to break off. Check the "Regular Expression" and "Multiline" boxes, then:
can only (|\\n)blink (|\\n)in (|\\n)astonishment (|\\n)at (|\\n)your (|\\n)astounding (|\\n)logic.
Every one of those (|\\n) is a potential line break. There could be a newline there, or there could be nothing. That way, no matter where the newline comes in that message, your trigger will match.
Have a look through the section on Regular Expressions in the MUSHclient help, and experiment lots with the "Test Trigger..." option. The only way you'll get the hang of it is by playing around. Explanations always sound unnecessarily complicated.
Tervic2006-08-01 15:19:42
QUOTE(vale_kant @ Aug 1 2006, 06:17 AM) 313523
Finally, note that you have to use regexes to do multiline triggers. Here's a neat thing for capturing warrior and debating messages, and other lines where you're not sure if you're going to run into a new line or not, nor where the line's going to break off. Check the "Regular Expression" and "Multiline" boxes, then:
can only (|\\n)blink (|\\n)in (|\\n)astonishment (|\\n)at (|\\n)your (|\\n)astounding (|\\n)logic.
Every one of those (|\\n) is a potential line break. There could be a newline there, or there could be nothing. That way, no matter where the newline comes in that message, your trigger will match.
THANK YOU so much. I was wondering how to do stupid multiline things, since the built-in multiline checking functionality in MUSH sucks monkey feet.
Unknown2006-08-01 15:31:58
thanks vale_kent! Thanks a billion! Hope this will help me get to making my personal triggers
Tiran2006-08-01 20:06:07
QUOTE(vale_kant @ Aug 1 2006, 07:17 AM) 313523
Finally, note that you have to use regexes to do multiline triggers. Here's a neat thing for capturing warrior and debating messages, and other lines where you're not sure if you're going to run into a new line or not, nor where the line's going to break off. Check the "Regular Expression" and "Multiline" boxes, then:
can only (|\\n)blink (|\\n)in (|\\n)astonishment (|\\n)at (|\\n)your (|\\n)astounding (|\\n)logic.
Every one of those (|\\n) is a potential line break. There could be a newline there, or there could be nothing. That way, no matter where the newline comes in that message, your trigger will match.
You'll want to be careful with how you express this. The server isn't guaranteed to send a space if that would push it past the end of the line. So a slightly safer way to do it would be:
can only( | ?\\n)blink( | ?\\n)in( | ?\\n)astonishment( | ?\\n)at( | ?\\n)your( | ?\\n)astounding( | ?\\n)logic.
That means there is either a space between the two words, or an optional space, followed by a newline. The ? after a character means match 0 or 1 of the character, in this case the space.
Unknown2006-08-01 22:28:03
can only ?\\n?blink ?\\n?in ?\\n?astonishment ?\\n?at ?\\n?your ?\\n?astounding ?\\n?logic\\.$
Unknown2006-08-02 02:08:55
QUOTE(Tiran @ Aug 1 2006, 09:06 PM) 313710
The server isn't guaranteed to send a space if that would push it past the end of the line.
Oh, cool, I was never quite certain how that worked. (And sorry about the unnecessary parentheses, I keep 'em 'cause I find it easier to interpret the pattern that way.)