What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [HELP]match New question Solved!

[HELP]match New question Solved!
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: [HELP]match
Aah, here comes on of the most beautiful features about JScript's replace function: you can use a regular expression combined with a custom replacement handler function!

First of all, you need to put what you want to find between parentheses in your regular expression. This way, the engine will capture these parts and pass them as parameters to your replace function or as properties of the global RegExp object (e.g. RegExp.$1). This will give you almost infinite control about how the replacing is done since you can do anything inside your handler, and it is something I use a lot in my scripts too.

Here is your code adapted with String.replace. As you can see, I got rid of your for-loop (in fact, you were better off with a while-loop there) and I made an example replacement handler function.
Javascript code:
sentenceT = sentenceT.replace(
    /\[t=(.+)\](.*?)\[\/t\]/gi, //The regular expression, note the parentheses to capture parts of our interest
    function(sMatch, $1, $2, nOffset, sFull) {  //We can use a function to do the replacing!
        if($1 === "ps") {
            //We found a [t=ps] match
            Time = $2;  //Set the Time variable to what's between the tags
            return "";  //Return an empty string to remove this match from the result
        }
        //Return the matched piece untouched if nothing was recognized
        return sMatch;
    }
);

Of course, if you have for instance 3 capture parts in your regular expression, you should place 3 receiving parameters in your handler function. Alternatively, you can leave out the last parameters (nOffset and sFull) if you don't need them.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
01-24-2009 11:11 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[HELP]match New question Solved! - by DaAniv on 01-24-2009 at 09:59 AM
RE: [HELP]match - by Danny22 on 01-24-2009 at 10:16 AM
RE: [HELP]match - by DaAniv on 01-24-2009 at 11:10 AM
RE: [HELP]match - by Matti on 01-24-2009 at 11:11 AM
RE: [HELP]match - by DaAniv on 01-24-2009 at 11:22 AM
RE: [HELP]match Solved - by Danny22 on 01-24-2009 at 11:38 AM
RE: [HELP]match new question - by DaAniv on 01-24-2009 at 12:19 PM
RE: [HELP]match New question - by Matti on 01-24-2009 at 12:49 PM
RE: [HELP]match New question - by DaAniv on 01-24-2009 at 01:44 PM
RE: [HELP]match Solved - by DaAniv on 01-24-2009 at 02:49 PM


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