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:
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. [?] "Dynamic" RegExp replace...
Not sure on the best way to go about this...

Here's an example of what I want to do.
JScript code:
// a "dynamic" object - identifiers will vary by function
var some_variables =
{
    foo: "some text",
    bar: "some more text"
};
 
// user input - can contain such variables when surrounded with "%"
var input = "I am writing %var:foo% here.";
var regex = /%var:([a-z]+?)%/gi;
var output = input.replace(regex, some_variables[regex.$1]);

...but I just get undefined from the RegExp.  Is there a way of doing this?
08-16-2011 05:57 PM
Profile E-Mail PM 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