[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Jscript
. . -> [Subject]  JScript AddTrigger with Regex
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

JScript AddTrigger with Regex

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


Posted by Mat   (14 posts)  [Biography] bio
Date Fri 16 May 2014 04:49 PM (UTC)
Message
I'm having some trouble with regex on an addtrigger in JScript. I've done this successfully in VBScript. I've also added the trigger successfully without the regex, but once the regex is added EVERY single line makes it trigger.
I don't understand what I'm doing wrong and why it's only in JScript. Mushclient v4.84

world.addtrigger("detect_exits", "[You can move: .*]", "", 33, 14, 0, "", "ExampleTrigger");
}
function ExampleTrigger (thename, theoutput, wildcardsVB)
{
wildcards = VBArray(wildcardsVB).toArray();

world.note ("Trigger " + thename + " fired.");
world.note ("Matching line was: " + theoutput);

for (i = 0; i < 10; i++)
if (wildcards != "")
world.note ("Wildcard " + i + " = " + wildcards );

}

Let me know if you can help in any way,
Thanks
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 16 May 2014 08:00 PM (UTC)

Amended on Sat 17 May 2014 05:16 AM (UTC) by Nick Gammon

Message

[You can move: .*]


The square brackets make a "set".

Template:regexp Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.


This matches any of those characters in the set, not just the sequence of them. That would match any line containing "Y", "o", "u" and so on, including the space character. Since most lines will have spaces in them, it will match most lines.

For example, this matches any line with a space in it:


[ ]


If the square brackets are part of the line "escape" them like this:


\[You can move: .*\]


In Jscript you might have to put the backslashes twice because a backslash means something to Jscript (eg. \n being a newline) so you need to double them to actually have the backslashes hit the regexp parser. eg.


 world.addtrigger("detect_exits", "\\[You can move: .*\\]", "", 33, 14, 0, "", "ExampleTrigger");

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Mat   (14 posts)  [Biography] bio
Date Reply #2 on Sat 17 May 2014 12:52 PM (UTC)
Message
You were right on the money Nick!
I did have the single backslashes, they just weren't displayed when I posted. The double backslashes did the trick.

Thanks very much, wasn't able to figure that one out on my own.
[Go to top] 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.


2,486 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]