Wildcards

Posted by 2009 on Thu 06 Mar 2008 09:12 PM — 3 posts, 19,849 views.

#0
Hi,

I'm new to this whole scripting and was wondering if there was a way to have varying number of wildcards in the one trigger.

I know i can do this:

Trigger: ^(.*?) says (.*?)$
Input: Greg says hi tony

And i assume wildcards [1] is "Greg" and wirldcards [2] is "hi tony".
Is it at all possible to have each word after the "says" a seperate wildcard, where the number of words can vary?(i hope that came out right :S)

thnx
Australia Forum Administrator #1
Not exactly as wildcards, because the wildcard numbers are assigned when the regular expressions is parsed for round brackets. However you can achieve it easily enough with a bit of scripting. For example:


<triggers>
  <trigger
   enabled="y"
   match="^(.*?) says (.*?)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
who = "%1"
said = "%2"

print ("speaker is " .. who)
print ("words are:")

for w in string.gmatch (said, "[%a%d]+") do
  print (w)
end -- for loop  
</send>
  </trigger>
</triggers>


See http://www.mushclient.com/pasting for how to copy and paste that example into the client.

On your test I saw this:


Greg says hi tony
speaker is Greg
words are:
hi
tony


Effectively I have used a Lua regular expression inside the script to break up what was said into words.

Another test:


Greg says this is a fine how do you do
speaker is Greg
words are:
this
is
a
fine
how
do
you
do

#2
Thanks Nick.