Larkin:
Quote: Your problem with losing the character may be due to that last part of your regular expression: "(\w+)(?: |)ray" where I don't think the (?: |) is really necessary. There will always be a space before ray, so just make it "(\w+) ray" instead, right?
But then you have the problem of the last {?:, | and | |) group, which already includes the space, so you'll have two spaces in the end in certain cases.
CroX:
Quote: Doesn't match..?
That's because I made a typo and you repeated it :P It should be:
^You are hit by a (indigo|yellow|green|violet|blue|red|orange|)(?:, | and | |)(indigo|yellow|green|violet|blue|red|orange|)(?:, | and | |)(indigo|yellow|green|violet|blue|red|orange|)(?:, | and | |)(indigo|yellow|green|violet|blue|red|orange|)(?:, | and | |)(indigo|yellow|green|violet|blue|red|orange|)(?:, | and | |)(indigo|yellow|green|violet|blue|red|orange|)(?:, | and | |)(indigo|yellow|green|violet|blue|red|orange|)(?: |)ray\.$
The very last captured group - (orange) originally - was missing a | to signify "orange or nothing". Hope it's right this time around, make sure all the colours are in there or it'll fail to match in some cases.
Quote: Furthermore, \w+ is much slower? I switched recently to MC from zMUD because of its speed, and so far most of my triggers uses \w+..
"Slow" in MC's terms normally means a difference of some 0.0005 seconds. But it's only as fast as you make it.
There are some tricks you can use to keep your entire system fast and it's a good idea to use them consistently, since
0.0005 seconds might not be a big deal but little things build up to large problems. One of the major tricks with
regexps is to make them as explicit as you can, since the less they have to guess, the faster they go, and the better
you can predict what they'll do.
Edit: You have been slain by the formatting monster. |