|
Haldrik Wanderer
Joined: 03 Sep 2007 Posts: 88
|
Posted: Wed Sep 19, 2007 11:12 am
RegEX list Vs Standard List (Triggers) Whats the difference? |
Ok so when I first started back scripting I didn't realize Zscript had a built in list trigger...
I.E. #Trigger {{(dog|cat|mouse)}}
So I started using #RegEx {(dog|cat|mouse)}
But then I remembered / found out how to use the Zscript listing for triggers :) Woohoo.
So, whats the difference in the two? I'm pretty sure RegEX can be a lot more complicated...
Is there an advantage of using the stand Zscript trigger?
Thanks :) |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Sep 19, 2007 11:43 am |
The advantage of zScript triggers is that they're simpler and easier to learn. It emulates most of the features of the regex engine, but not all of them, and so regex is more powerful. Internally, zScript patterns are expanded into regexes anyway (you can see the regex on the Test Trigger tab of a trigger).
Also, the correct syntax for a zScript list is {one|two|three}, and the correct syntax for a regex list is (one|two|three). zScript's {one|two|three} expands to (?:one|two|three), so if you want it captured to a %nn variable, you need to use ({one|two|three}). Also note that other wildcards don't work inside the zScript list syntax. |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Wed Sep 19, 2007 2:52 pm |
Yes, the big advantage to regex is that you can use patterns inside that.
(?:dogs?|cats?) |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Sep 20, 2007 12:41 am |
On the other hand, regex triggers are totally dumped into the regex dll. There's no optimization going on, which could cause some tiny bit of speed loss (probably no longer noticeable in CMud, though, unless you're really robust with your package setups.)
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Haldrik Wanderer
Joined: 03 Sep 2007 Posts: 88
|
Posted: Thu Sep 20, 2007 2:08 am |
Ahhhh. Sounds like I don't necessarily need to use RegEx then.
Ok, another question then, not sure which would be better, RegEx or Zscript.
My list
Trigger: {crystal|amulet|stone|pink stone|pink}
get %1
--------------------------------
Ok, so on trigger "crystal amulet" it would do "get crystal" whereas "stone amulet" would "get stone". When I need it to "get amulet". Also "green amulet" would of course "get amulet".
Other items include, "yellow crystal" which would "get crystal". Which is what I want it to do.
How can i make trigger on the amulet first? Or in the case of "pink stone" to get "stone" and not "pink"?
Thanks guys :) |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Thu Sep 20, 2007 3:15 am |
Try (regex):
(?:(?:crystal|stone) )?(amulet|crystal|stone)
get %1
Edit: I think ? is greedy, which would be why that would work, if not, try:
(?:(?:crystal|stone) )*(amulet|crystal|stone)
Because I know * is greedy. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Sep 20, 2007 9:09 pm |
{color|list|here} {item|list|here}
If items can have more than one adjective, then you'll need * or something similar to match the in-between stuff (*, [%w%s], etc). Another way is to simply capture the entire item name and use %word(%1,%numwords(%1)) to draw out the item keyword. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Sep 21, 2007 2:01 pm |
What do you mean about zScript patterns being optimised, Matt? I was under the impression that CMUD just parses the pattern into a regex, which is then compiled by the regex dll same as any other regex. So CMUD patterns would be slower once, until the pattern was compiled, and then there'd be no difference.
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Fri Sep 21, 2007 10:06 pm |
It does, but as I understand it Zugg's doing things when converting a zscript pattern into regex that are not being done when the pattern is already regex. He explained it in an old zmud question on #REGEX, but as far as I know that wasn't changed in CMud.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Sep 24, 2007 8:15 pm |
These days there should be very little difference in speed between zScript and RegEx patterns. As mentioned, zScript patterns are converted into regular expressions the first time they are compiled. The only advantage to zScript when using the {a|b|c} syntax is that CMUD sorts your list when converting it to a regular expression.
The advantage of zScript patterns is the simpler syntax. For example, %w in zScript will handle non-English alphabetic characters, so it's a bit better than \w+ in RegEx (in fact, %w really gets converted into a long [A-Za-z...] character range that includes all of the upper-bit non-English alphabetic characters).
For people who don't already know regular expressions, zScript is easier because it treats wildcards such as * the same way the file system does. But if you already know RegEx syntax, then RegEx can be a bit more powerful. |
|
|
|
|
|