What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [?] "Dynamic" RegExp replace...

[?] "Dynamic" RegExp replace...
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: [?] "Dynamic" RegExp replace...
The reason why your version won't work is because regexp.$1 is evaluated once when that line is run.

However, you can still do this without a for-loop and lots of replace calls. JScript allows you to pass a function as second parameter for replace, whose return value will be used as replacement for each match. When using regular expressions, it'll even give you all the good stuff through the function's arguments!
js code:
var output = input.replace(regex, function(match, $1) {
    // You could do literally anything here!
    return ($1 in some_variables) ? some_variables[$1] : '';
});
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
08-17-2011 02:22 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[?] "Dynamic" RegExp replace... - by whiz on 08-16-2011 at 05:57 PM
RE: [?] "Dynamic" RegExp replace... - by Eljay on 08-16-2011 at 06:19 PM
RE: [?] "Dynamic" RegExp replace... - by whiz on 08-16-2011 at 06:54 PM
RE: [?] "Dynamic" RegExp replace... - by Matti on 08-17-2011 at 02:22 PM
RE: [?] "Dynamic" RegExp replace... - by whiz on 08-17-2011 at 06:20 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