I have a string which looks like below
Your statistics:
The trend is going up.
The most recent value for x*y on 2018-12-09 is 469.44.
The max was 2896 on 2018-12-08 and min was 23.1 on 2018-12-08.
Additionally, the median is 367.95 and the mode is 23.1.
There is higher margin for error/mistake.
As you can see I got some float
and int
in the string. I need to replace all those occurences with span
tag surrounding those occurrences
Here I managed to do something basic like replacing the instances of float
and int
with XXX
. But the problem is there are occurrences of date
too and that screws up the operation. So this is what I do:
var string = "Your statistics:<br>The trend is going up.<br>The most recent value for x*y on 2018-12-09 is 469.44.<br>The max was 2896 on 2018-12-08 and min was 23.1 on 2018-12-08.<br>Additionally, the median is 367.95 and the mode is 23.1.<br>There is higher margin for error/mistake."
string = string.replace(/\d+/g, "XXX");
console.log(string)
This is what I get:
Your statistics:<br>The trend is going up.<br>The most recent value for x*y on XXX-XXX-XXX is XXX.XXX.<br>The max was XXX on XXX-XXX-XXX and min was XXX.XXX on XXX-XXX-XXX.<br>Additionally, the median is XXX.XXX and the mode is XXX.XXX.<br>There is higher margin for error/mistake.
Now what I want is replace all occurrences of float
and int
with a span
tag surrounding them something like 469.44
be replaced with <span>469.44</span>
, 2896
be replaced with <span>2896<span>
So final string would become something like:
Your statistics:<br>The trend is going up.<br>The most recent value for x*y on 2018-12-09 is <span>469.44</span>.<br>The max was <span>2896</span> on 2018-12-08 and min was <span>23.1</span> on 2018-12-08.<br>Additionally, the median is <span>367.95</span> and the mode is <span>23.1</span>.<br>There is higher margin for error/mistake.
How do I accomplish this ensuring dates
are not messed up?