Shielding Regexes and matches

Post Reply
sykellus
Posts: 2
Joined: Wed Jan 12, 2011 5:27 pm

Shielding Regexes and matches

Post by sykellus »

So I recently read on these forums about "shielding" regex triggers, so I went to try this out and I encountered a problem.

The trigger I'm using is meant to trigger off of "^You remove (.+)\.$". When I created the shield, I made it an AND trigger with Line Delta of 0. I made the 0th pattern a begin-of-line substring that matched "You remove" and then the 1st pattern a perl regex of "^You remove (.+)\.$"

In my script, I want to use the match of (.+). I know the trigger is matching the text from the MUD because I tested it using an echo. However, the matches table is completely empty, which means I can't use the captured string of what I removed in my script. Can someone tell me how to correct this? Thanks.

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Shielding Regexes and matches

Post by Yetzederixx »

I understand the beginning line matches are faster, but are they really faster than a trigger firing twice?

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Shielding Regexes and matches

Post by Iocun »

sykellus: If you have a multiline/AND trigger, the matches won't be saved in "matches" but in "multimatches". Instead of matches[2] you'd have to use multimatches[2][2] to get first matched part of the second pattern. (multimatches[2][1] for instance would encompass the whole matched line of your second pattern, the regex one.)

Yetzederixx wrote:I understand the beginning line matches are faster, but are they really faster than a trigger firing twice?
Since I don't know how triggers are implemented exactly, I can only make guesses:
First of all, the important thing is that it will -only- "match twice" if the parent trigger already fired. If the parent trigger didn't fire, the second doesn't need to be tested, and seeing that most triggers will fire only on a very small percentage of the lines you receive, the impact of shielded regexes having to "match twice" is a LOT smaller than that of a ton of unshielded regexes that have to be checked on every single line.

So the speed gain probably mostly depends on how often the trigger is going to match. If you have a trigger that will match very often, the gain of shielding will be smaller. But if you have a trigger where the parent (your begin of line/exact match/whatever) will already rule out most of the lines as non-matches, shielding will be quite a big advantage in speed.

Post Reply