scriptingmirc

mIRC/mSL pulling certian strings out of a wildcard


So I'm pretty new to mSl scripting, but I've done some other scripting before. I'm trying to figure out how to do some pattern matching, but I'm having a problem. Let's say I have the following text

Someone has flipped a coin to Jim and it was head.

I'm wanting to find out if the coin ended up being heads or tails. I thought it would be something like

on *:text:*flipped a coin * and it was *:#:{echo -a the coin was $3}

but it seems like the $ operator is taking the 3rd word from the complete wildcard. I might be able to figure out how to get it right with this example, but lets say we have the following examples with multiple coins

Someone flipped a coin to Dave and it was tails, and also filled a coin to Jim and it was heads.

I'm wanting to find out what coin Jim had, but I don't know how many people were before or after him, so finding the xth word in my wild card won't work. What i'd like to do is something like this (mostly sudo code)

on *:text:$1 * to Jim and it was $2:#:{ 
    echo -a $1 is who flipped it to Jim and it was $2
}

Where I can basically throw out my wildcards and now i can directly reference who the coin flipper was, and what the results were.

Thanks for any help!

Edit:

I'm able to find the find the coin result with regex, but I'm not sure how to pull the result out in mirc. See the regex pattern i'm using here . I tried using $regex in mirc and also $regml, but it's not working right. I currently have the following in my script:

on $*:text:/Jim and it was (\b\w{5}\b)/iS:#:{
echo -a $regex(currCoin, $1-,Jim and it was (\b\w{5}\b))
echo -a $regml(currCoin,0)
echo -a $regml(currCoin,1)
}

I thought $regex would essentially save the groups from my regex to currCoin, and then $regml would display the Nth group value, sort of like $N would show the Nth group value in regex. I'm clearly miss understanding something though.


Solution

  • You can use token identifiers instead of regex for this. I haven't used msl for at least 10 years, so bear with me.

    on *:text:*to Jim and it was*:#:{
      var %jimpos = $findtok($1-,Jim,1,32)
      var %coinpos = %jimpos + 4
      var %result = $gettok($1-,%coinpos,32)
      msg $chan $remove(%result,.)
    }
    

    You can possibly shorten it somewhat or do more operations on the same line, but this is readable at least.