Nested patterns in alternatives- how to wildcard?

Posted by Renweiii on Mon 12 May 2014 04:13 PM — 3 posts, 13,618 views.

#0
Have a regexp as follows:

^Peter kicks (.+)|Bob punches (.+)|Josh bites (.+)$

%0 returns the whole string as expected. %1 is empty, however. Naming does not seem to change anything. Is there some way to capture the matching (.+) for all alternatives without rewriting this as three separate triggers?

Cheers and sorry for any trouble!
Australia Forum Administrator #1
The simple answer is that you get back the name in %1, %2 or %3 which you could easily check in a script.

However to get them all into the same wildcard, you need to use named wildcards (with the same name) and use the (?J) option at the very start, to allow duplicates. For example:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="(?J)^Peter kicks (?&lt;who&gt;.+)|Bob punches (?&lt;who&gt;.+)|Josh bites (?&lt;who&gt;.+)$"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>who = %&lt;who&gt;</send>
  </trigger>
</triggers>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


The wildcard without the XML around it is:


(?J)^Peter kicks (?<who>.+)|Bob punches (?<who>.+)|Josh bites (?<who>.+)$


Output:


Peter kicks Fred
who = Fred
Bob punches James
who = James
Josh bites the dog
who = the dog
Amended on Mon 12 May 2014 08:30 PM by Nick Gammon
#2
Ah, nice, thanks!