Test string.replace
by Johnny Lee
JavaScript
function f2c(x)
{
function convert(matched, p1, offset, str)
{
return ((p1-32) * 5/9) + "°C";
}
var s = String(x);
var test = /(\d+(?:\.\d*)?)°F\b/g;
return s.replace(test, convert);
}
document.write(f2c("32°F to 212°F"));