Actually grabbing all regular expressions matches

Posted by Macai on Wed 25 Oct 2006 07:59 AM — 4 posts, 16,904 views.

#0
I have discovered a bit of a problem with the wildcards variable in triggers. If it's not a "wildcard" it doesn't appear as an option. For example the pattern "^You see exits leading (north|northeast|east|southeast|south|southwest|west|northwest|up|down|in|out) and (north|northeast|east|southeast|south|southwest|west|northwest|up|down|in|out).$"

Will not return the north/northeast regular expression matches in the wildcards. So, I got PHPScript to work on MUSHClient and I fixed this problem.
function MyTriggerFunctions($name,$line) {
	$pattern=$world->gettriggerinfo($name,1); // grab the regular expressions pattern of the trigger
	ereg($pattern,$line,$wildcards); // dumps all the actual wildcards results into the variable $wildcards

	$world->Note(print_r($wildcards,true)); // this just displays that $wildcards array
}
There's my workaround for this, just in case someone wants to do some weird stuff with regular expressions and actually grab the results. ;)

Another benefit of this method is it does not limit you to ten regular expressions wildcards--you can have as many as you like, with any language!

I hope someone finds use for this, and I apologize if this subject is already covered in some way.

-- Macai
Amended on Wed 25 Oct 2006 08:03 AM by Macai
Australia Forum Administrator #1
I'm not sure what you mean by this, as it works perfectly:


<triggers>
<trigger
enabled="y"
match="^You see exits leading (north|northeast|east|southeast|south|southwest|west|northwest|up|down|in|out) and (north|northeast|east|southeast|south|southwest|west|northwest|up|down|in|out).$"
regexp="y"
send_to="2"
sequence="100"
>
<send>%%1 = %1
%%2 = %2</send>
</trigger>
</triggers>


If I try that I get something like this:


%1 = north
%2 = east


Also, the standard regular expressions can have up to 999 wildcards, you can access them in various ways, here is one:

http://www.gammon.com.au/scripts/doc.php?function=GetTriggerWildcard

Also you can refer to wildcards larger than 9 in the "send" box like this:

%<45>
#2
Well this is odd, then, if it works for everyone else.

I did notice that it does not work for PHPScript as is, WHEN I use the built-in GUI to edit triggers. :(

It might work for everything else, however.

Thanks!

--Macai
Australia Forum Administrator #3
It would be helpful if you posted the entire trigger, see this post for how to do that:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4776

Perhaps your problem is the way you accessed the wildcards.