Thursday, 18 May 2017

Trying to remove only the characters F or C following numbers

I'm trying to find a regex (that will work in node.js) to remove the Fahrenheit and Celsius letters and replace them with " degrees" from the below weather forecast string.

"Clear skies. Low 46F. NNW winds shifting to ENE at 10 to 15 mph."

I want the above string to read as below:

"Clear skies. Low 46 degrees. NNW winds shifting to ENE at 10 to 15 mph."

There could be more than one instance of a temperature in the string.

NOTE: I only want to remove the F or C if it's immediately following a number with no space in-between. If "Florida" were in the above string, I'd want the letter "F" left untouched.

I've tried the below regex, but it finds the entire 46F. I just want it changed to 46 degrees.

/\d+[FC]/g

Thanks.



via Kevin Key

No comments:

Post a Comment