Shoutbox

RegExp help/Alternative? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: RegExp help/Alternative? (/showthread.php?tid=88328)

RegExp help/Alternative? by ArkaneArkade on 01-12-2009 at 02:39 AM

Hey guys, as always, stuck again.
I'm trying to sort out some information from a CurrentMedia string using RegExp, but I'm nowhere near good enough at it (or understand it well enough).

code:
XBOXMSGR\0Game\01\0{0}: {1} ({2})\0Xbox 360\0Game Name\0GamerTag\0Web-Link\066262\0\0
code:
ITunes\0Music\01\0{0} - {1}\0Song\0Artist\0Album\0"

Both of these strings are taken from different Media strings by different (yet default MS) apps.  Both of them have different numbers of dividers (the "\0") and I think this is where my problems are occurring.
I was trying to use a function to retrive the information, but because I'm unsure how to make each section optional I can't get it to retrieve the final sections without stopping it working.

Lastly (I know, taking liberties now) I'd like to know if there is a way to return multiple values, so that I could set up the function to get the information I need

For example, after running the RegExp, is there a way to return $1, $2, $3, falling back onto $1, $2 if there is no $3 (etc all the way up to the 10 or whatever the value is).  The on the other end, to get just the one I want from the function (ie if the function is RunReg(), to do something such as "var variable = RunReg(2) to retrieve the second value?

can anyone help me with any of this?  I would be extremely grateful...
Cheers guys
Leroux
RE: RegExp help/Alternative? by Spunky on 01-12-2009 at 03:00 AM

You can return an array...

js code:
function RunReg(){
    var myArray = new Array();
    myArray[0] = "Blah";
    myArray[1] = 404;
    myArray[2] = "example";

    return myArray;
}

function OtherFunction(){
    var ret_val = RunReg();
    Debug.Trace(ret_val[1]);
}

EDIT: Also. If you put the media message in a string:

js code:
media_string = media_string.split("\0");
for(var s in media_string){
    //Do things for each section
}

RE: RE: RegExp help/Alternative? by ArkaneArkade on 01-12-2009 at 03:32 AM

Thanks you Spunky.  I never considered doing it that way, but because of that quick reply, I have it all sorted now:D

Only one note:

quote:
Originally posted by Spunky

js code:
media_string = media_string.split("\0");

To work properly, needs to be
js code:
media_string = media_string.split("\\0");

Cheers man
RE: RegExp help/Alternative? by Spunky on 01-12-2009 at 03:44 AM

quote:
Originally posted by Leroux
To work properly, needs to be
Javascript code:
media_string = media_string.split("\\0");

Cheers man

:p You knew what I meant though ;)

And np.