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.
Entire forum
➜ MUSHclient
➜ Jscript
➜ JScript AddTrigger with Regex
JScript AddTrigger with Regex
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Mat
(14 posts) 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) 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
|
The square brackets make a "set".
|
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:
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 | Top |
|
Posted by
| Mat
(14 posts) 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. | 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.
14,987 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top