I have a string that was retued from an API, and I want to add in degree symbols from the temperatures that are included ("Tomorrow will be a high of 89F" → "Tomorrow will be a high of 89°F"). What would the Regex look like for my variable named forecastString?
This replace will work:
forecastString = forecastString.replace(/[0-9]{1,3}F/g, function addDegreeSymbol(x){retu x.replace("F", "°F");});
forecastString = forecastString.replace(/[0-9]{1,3}C/g, function addDegreeSymbol(x){retu x.replace("C", "°C");});
The Regex finds any numbers of 1-3 digits followed immediately by an F/C, and replaces the F/C with °F/°C
برچسب:
نویسنده: استخدام کار
تاريخ: يکشنبه
3 مرداد
1395 ساعت: 1:18