double send on regular expression match

Posted by Essidus on Sun 05 Feb 2006 08:04 PM — 8 posts, 28,791 views.

#0
On a regular expression trigger I use that gets fired on my mu*'s system messages as thus:
\n          [\*\*\*\*\*\*\*\*\*\*\*\*\-\-Rumour Monger\-\-\*\*\*\*\*\*\*\*\*\*\*\*]\n(.*)\n          [\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*]\n\Z


and sends a simple note

note "trigger matched, %1 as wildcard"


has been doubling. I've checked the trigger info, and it seems to fire twice every time it matches. Anyone have a solution for me?
Russia #1
It's surprising that it matches at all, since technically it shouldn't. Are you sure that there are no other triggers that could be matching that output? Because I really don't see how that regular expression could match what you seem to be trying to match. It should match on stuff like:


        *
Blah
        *


or


        R
Blah
        *


Since you have two character classes in there, each matching exactly one character.

In any case, try the following pattern instead, it seems to match without any surprises and is considerably faster:

\n          \*{12}\-\-Rumour Monger\-\-\*{12}\n(.*)\n          \*{41}\n\Z
#2
There were a couple of brackets missing on your version of the string, but no matter. More importantly, I got the same effect as before. The trigger itself is listing as being matched twice for every group matched, so that the results come out like this:


          [************--Rumour Monger--************]
           Player arrives in Game.
          [*****************************************]
Script triggered.            Player arrives in Game. returned
Script triggered.            Player arrives in Game. returned


Now, just like last time, in the trigger information itself, it's saying it's getting called twice.
Australia Forum Administrator #3
How many lines have you set the trigger to match on?
Australia Forum Administrator #4
Quote:

[\*\*\*\*\*\*\*\*\*\*\*\*\-\-Rumour Monger\-\-\*\*\*\*\*\*\*\*\*\*\*\*]


Apart from being tedious, this just looks wrong. You haven't escaped the bracket on the left or right, so you really matching on a "set" of characters, consisting of asterisks, any of the letters in "Rumour Monger" and so on.

The middle bit (I haven't counted the spaces) should look like this:


\[\*{12}\-{2}Rumour Monger\-{2}\*\{12}\]


Note the backslash before the square brackets.
#5
Right, I'm using the changed code now, but it still gets doubled triggers, as if the trigger gets called twice, which is proven correct in the trigger edit window's call # (It goes up by two with every one match). There is only one call, and it matches five lines, those five being two blank lines, and the three with characters in them.
Australia Forum Administrator #6
OK, I see what you mean. You actually had the backslashes there, they just didn't show up in the forum posting. You need to "quote forum codes" when posting stuff with square brackets in it, there is a function in the MUSHclient notepad to do that.

I fixed the problem by adding \A to the very start of the regular expression. I think the problem is that you are matching 3 lines in the regular expression, but taking 5 lines in your trigger. Thus there is the potential for the match to occur twice.

Either cut down the match count to 3, or actually put the blank lines into the regexp.

The \A that I put in says "match start of subject" so that is an assertion that the trigger is the start of the subject (that is, the start of the 5 lines).
#7
That worked perfectly! Thank you.