
Regular Expression Replace Question
Quoted directly from the JScript Language Reference:
The following example, which works in JScript 5.5 and later, performs a
Fahrenheit to Celsius conversion, illustrates using a function as
replaceText. To see how this function works, pass in a string containing a
number followed immediately by an "F" (e.g., "Water boils at 212").
function f2c(s) {
var test = /(\d+(\.\d*)?)F\b/g; //Initialize pattern.
return(s.replace
(test,
function($0,$1,$2) {
return((($1-32) * 5/9) + "C");
}
)
);
Quote:
}
document.write(f2c("Water freezes at 32F and boils at 212F."));
JScript Documentation
http://msdn.microsoft.com/scripting/jscript/download/jsdoc.exe
http://msdn.microsoft.com/scripting/jscript/techinfo/jsdocs.htm
=-=-=
Steve
-=-=-
Quote:
> I'm trying to write a regex replace that works something like this:
> some_string.replace(regex_stuff, do_something_to("$1"))
> Where I want to pass the match ($1) to some function for manipulation
> because what I want to do is too complicated to be done with a managable
> regular expression. Can I pass the match to a function like this?
> Tim