quote:Originally posted by deAd
It wasn't in reply, it was just a note
EDIT: Also, I posted an example of using a function in String::replace earlier in this thread...just that my regex was a bit off..
your function was a bit off too...
it worked but you let replace search with a regular expression and when it found a match you searched the string again for that same match, while it already found the match in the first place. In short: your function didn't made much sense logically (aka doesn't teach the proper thing). What you did was like asking a doctor to examine you, and when he lists the problems, you say: screw it, I'll search it myself using that medical reference...
correct way:
code:var s = "Hello there, 1+1 should be 2. And 5-2 will be 3.";
s = s.replace(/([0-9*/+\-()]+)/gi, function($0, $1) { return eval($1) });
Debug.Trace(s);
This post was edited on 09-29-2006 at 12:59 AM by CookieRevised.