Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Tips and tricks ➜ Variables in Regular Expressions

Variables in Regular Expressions

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Goldenfire   (4 posts)  Bio
Date Tue 23 Mar 2004 03:20 AM (UTC)

Amended on Tue 23 Mar 2004 03:22 AM (UTC) by Goldenfire

Message
(I use MUSHCLient 3.45, just so you know :)

I currently have a variable (wf_people), of the form "foo|bar|bah|baz"

I then tried to make a trigger "^.*(?:@wfpeople).*$"

If I did the sustituion by hand (i.e. put "foo|bar|bah|baz" in the trigger) the trigger fires correctly. If I put it with @wf_people, however, it does not. I have "Enabled', "Ignore case", "Keep Evaluating", "Regular Expression", and "Expand variables" checked.

Am I just missing something stupid, or is it trying to treat the "|" in the variable as literals, or something else entirely?

(edited for stupid typos...Doh!)
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 23 Mar 2004 03:23 AM (UTC)
Message
The problem here is that MUSHclient tries to be smart, and assumes that if you have a special character (eg. "(") inside your variable, that it needs to be "escaped" by putting a \ in front of it, when inserting it into a regular expression.

The only real workaround here is to assemble the trigger by hand. That is, whenever you change the variable (eg. using an alias) reassemble the trigger.

There is a recent example of doing exactly that, as I had the same problem recently making a "gag" plugin. See how it was done here:

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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 23 Mar 2004 03:25 AM (UTC)
Message
See this part in particular:


Sub MakeTrigger
 
'
'  remember gag list in variable for plugin state save
'
  SetVariable "gags", ArrayExport ("gags", "|")
'
'  enable/disable trigger depending on whether we have gagged players
'
  EnableTrigger "gags", ArraySize ("gags") <> 0
'
'  change the trigger match text - replace !! by the gag list
'
  If SetTriggerOption ("gags", "match", _
     Replace (GetVariable ("regexp"), "!!", _
     ArrayExportKeys ("gags", "|"))) = eBadRegularExpression Then
    ColourNote "white", "red", _
      "Could not set trigger - check regular expression syntax"
    ColourNote "white", "red", "Regular expression is currently: " _
      & GetVariable ("regexp")
  End If

End Sub


This code keeps the "original" regular expression in a variable, and replaces the !! part of it with the variable contents.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Goldenfire   (4 posts)  Bio
Date Reply #3 on Tue 23 Mar 2004 03:44 AM (UTC)
Message
Since I was already generating the pipe-delimited list from a perlscript, it was relatively trivial to add the SetTriggerOption line :)

Have you considered, potentially, either:
a) making variables-in-regular-expression perl like (thereby requiring something like perls qw() function)...admittedly, this would break lots of things
b) adding something that's more-or-less the _opposite_ of qw(). Thereby informing any regexps that the variable is in to _not_ escape metachars.

Either of those would be nice, and would make the trigger much more readable :)
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #4 on Tue 23 Mar 2004 04:23 AM (UTC)
Message
It's a nice idea - I'll put it on the list of suggestions.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Goldenfire   (4 posts)  Bio
Date Reply #5 on Tue 23 Mar 2004 04:50 AM (UTC)
Message
Just as a note, because I hate when I post mis-information, the perl function is quotemeta() not qw

qw// does something entirely diferrent, even if the command is much shorter :)
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #6 on Mon 26 Apr 2004 02:22 AM (UTC)
Message
Version 3.48, now released, lets you do this:

@!people

This tells MUSHclient to not escape the meta-characters.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Goldenfire   (4 posts)  Bio
Date Reply #7 on Mon 26 Apr 2004 02:34 AM (UTC)
Message
sweeeeeeeeet :)

thanks muchly!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


24,617 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.