What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Gettin data from "/" commands

Gettin data from "/" commands
Author: Message:
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: Gettin data from "/" commands
I just wanted to update Cookie's regex to something that is a little better IMHO

code:
if (/^\/([^\s\/]\S*)\s*(.*)/.exec(sMessage) !== null) {

Cookie's old code didn't allow for / to be used elsewhere through the command (you can't use it to begin the command, but it is possible to use it later.  There is no point having $ at the end of the expression due to the greedy nature of quantifiers.  And finally [\s\S] is simply the equivalent of ".".

I think I should also give people an example of having parameters that are ALWAYS a single word, it is best to use the following instead:

code:
if (/^\/([^\s\/]\S*)\s*(\S*)/.exec(sMessage) !== null) {

and then for multiple paramters seperated by spaces (you will still need to do a split on the RegExp.$2 variable to get all of these variables seperated, or use of methods involving regex if you want to avoid blank variables):

code:
if (/^\/([^\s\/]\S*)\s*((?:\S+\s)*)/.exec(sMessage) !== null) {

If you want a different way to seperate between the parameters then you can use something like square braces (ie. "[param and with spaces]").  I'll use up to 3 params in this example:

code:
if (/^\/([^\s\/]\S*)\s*(?:\[.*?\]\s*(?:\[.*?\]\s*(?:\[.*?\])?)?)?/.exec(sMessage) !== null) {

This then becomes useful for when you are trying to find matching Plus! tags.  But this is getting off-topic and a lot more advanced when it comes to Regex.  If you have any questions, or want to see some other examples then please ask and I'll be happy to help (better to do it here so everyone can apreciate the beauty of regex)
[Image: markee.png]
02-04-2008 11:52 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Gettin data from "/" commands - by Lobo on 05-22-2007 at 07:46 PM
RE: Gettin data from "/" commands - by saralk on 05-22-2007 at 08:03 PM
RE: Gettin data from "/" commands - by vikke on 05-22-2007 at 08:05 PM
RE: Gettin data from "/" commands - by markee on 05-22-2007 at 08:59 PM
RE: Gettin data from "/" commands - by DarkGhost on 05-22-2007 at 11:41 PM
RE: Gettin data from "/" commands - by CookieRevised on 05-23-2007 at 12:09 AM
RE: Gettin data from "/" commands - by DarkGhost on 05-23-2007 at 12:32 AM
RE: Gettin data from "/" commands - by CookieRevised on 05-23-2007 at 12:56 AM
RE: Gettin data from "/" commands - by Lobo on 05-23-2007 at 07:14 PM
RE: Gettin data from "/" commands - by markee on 02-04-2008 at 11:52 AM
RE: Gettin data from "/" commands - by CookieRevised on 12-07-2009 at 01:39 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