What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Release] Exit WLM

[Release] Exit WLM
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: RE: [Release] Exit Messenger - script attached
quote:
Originally posted by Jesus
code:
var str = "The quick brown fox jumps over the lazy dog.";
return str.split(" ",2);
will return a 2-element array: "The,quick"
You are correct (Y)(Y)

The reason of my mistake is because at that time I was busy with VB6 and in VB6 the limit parameter limits the amount of array elements without loosing anything from the string. In JScript it does loose all the rest of the string.

quote:
Originally posted by markee
I think what you are after in regular expressions is the follow, though if someone is will to suggest a better regular expression I will be happy to accept it (assuming it works).
code:
if((arr = /\/([^ \s]*) (.*)/i.exec(stringObj) != null){
var command = arr[1];
var param = arr[2];
}

almost, since that regular expression does not work properly.

What you need to take in account:

- a command always starts with only 1 slash "/" (not two, or more)
^^ your reg exp fails here since you don't exclude second or more slashes.

- after the slash there can not be a spacing character
^^ your reg exp fails here since you define the exclussion list to be 0 or more times ("*") when it should be 1 or more times ("+").
PS: a space (ascii 32) is also a spacing character ("\s") so you don't need to define that seperatly in the exclussion list.


- commands should be case insensitive, but parameters are not!
^^ your reg exp fails here since you don't lowercase the command. Yet you use the case insensitive marker. But this does not do anything, since there are no characters in the regular expression. That marker is for searching on all cases, not to convert cases.

- after the command there can be many spacing characters. In many cases (if not all), the user/coder simply wants the parameter to begin without any spacing characters. But Plus!'s default behaviour is to take every occuring spacing character after the first spacing character after the command as part of the parameter (though not that usefull for almost all scripts).
^^ your reg exp fails here since you don't specify a spacing character ("\s") but only a space (ascii 32).

- a parameter can contain multiple lines.
^^ your reg exp fails here too since you check on 'any' character ("."),  but 'any' character does not include new line characters ("\n").


A more accurate regular expression to seperate the command and parameter which is also already used in my Exit Messenger script:
code:
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null) {
        var command = RegExp.$1.toLowerCase();
        var parameter = RegExp.$2;
        switch (command) {
            case 'quit':
                // <- Do something when the user typed the command quit
                return '';
            case 'exit':
                // <- Do something when the user typed the command exit
                return '';
            case 'cancel':
                // <- Do something when the user typed the command cancel
                return '';
        }
    }
}
In above snippet:
- to let the parameter include all leading spacing characters like Plus! nativly does, change  \s* or  \s?
- to dismiss any trailing spacing characters after the parameter, you could replace  ([\s\S]*)  with  ([\s\S]*?)\s*

If you only have 1 command in your script (eg: /explode) your can use something like:
code:
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    if (/^\/explode(?:\s+([\s\S]*)|$)/i.exec(sMessage) !== null) {
        var parameter = RegExp.$1;
        // <- Do something when the user typed the command explode
        return '';
    }
}
In above snippet:
- to let the parameter include all leading spacing characters like Plus! nativly does, change  \s+  to  \s{1}

;)

--------------

PS: note that I talk about spacing characters. But in fact Plus! doesn't consider all spacing characters as spacing characters. the tab character is a spacing character, but Plus! handles this as a normal non-spacing character. So the above regular expressions aren't entirly 100% like Plus! behaves though. But I'm too tired atm to make them exactly alike. Though, for most people the above will be more than sufficient and accurate enough (especially since most would only use things like split(), substr(), etc anyways).

EDIT: More accurate regular expressions to handle Plus!-style commands and a detailed explanation of them can be found here:
post 1: CookieRevised's reply to Gettin data from "/" commands
post 2: CookieRevised's reply to Gettin data from "/" commands

This post was edited on 03-25-2011 at 12:10 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
12-19-2006 12:27 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Release] Exit WLM - by Spunky on 11-13-2006 at 03:07 AM
RE: [Release] Exit WLM - by NanaFreak on 11-13-2006 at 03:12 AM
RE: [Release] Exit WLM - by MicroWay on 11-13-2006 at 03:16 AM
RE: [Release] Exit WLM - by markee on 11-13-2006 at 03:19 AM
RE: [Release] Exit WLM - by Spunky on 11-13-2006 at 03:21 AM
RE: [Release] Exit WLM - by matty on 11-13-2006 at 03:51 AM
RE: [Release] Exit WLM - by markee on 11-13-2006 at 03:58 AM
RE: [Release] Exit WLM - by CookieRevised on 11-13-2006 at 04:06 AM
RE: [Release] Exit WLM - by matty on 11-13-2006 at 05:22 AM
RE: [Release] Exit WLM - by Spunky on 11-13-2006 at 07:48 PM
RE: [Release] Exit WLM - by Matti on 11-13-2006 at 08:16 PM
RE: [Release] Exit WLM - by Spunky on 11-13-2006 at 08:23 PM
RE: [Release] Exit Messenger - script attached - by CookieRevised on 11-15-2006 at 12:14 AM
RE: RE: [Release] Exit Messenger - script attached - by Jesus on 12-18-2006 at 01:37 PM
RE: RE: RE: [Release] Exit Messenger - script attached - by markee on 12-18-2006 at 02:06 PM
RE: RE: RE: [Release] Exit Messenger - script attached - by CookieRevised on 12-19-2006 at 12:27 AM
RE: RE: RE: RE: [Release] Exit Messenger - script attached - by markee on 12-19-2006 at 02:02 AM
RE: [Release] Exit WLM - by Spunky on 11-15-2006 at 12:29 AM
RE: [Release] Exit WLM - by CookieRevised on 11-15-2006 at 01:17 AM
RE: [Release] Exit WLM - by Aristide on 12-17-2006 at 01:56 PM
Re; [Release] Exit WLM - by BraydenP on 12-18-2006 at 12:37 PM
RE: [Release] Exit WLM - by CookieRevised on 12-19-2006 at 02:06 AM
RE: [Release] Exit WLM - by Spunky on 12-19-2006 at 02:08 AM
RE: [Release] Exit WLM - by warmth on 12-22-2006 at 11:38 PM
RE: [Release] Exit WLM - by Spunky on 12-23-2006 at 01:27 AM
RE: [Release] Exit WLM - by warmth on 12-23-2006 at 08:33 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On