I'm using Regex to bold characters using a double underscore. This is my regex, which works:
"I'm making __this__ bold".replace(/\__([^*]+)\__/g,"<b>$1</b>");
Which gives me this:
"I'm making <b>this</b> bold"
But how do I get it work with React? I have the following code, which doesn't work:
{cars.map(car => {
return (
<div>
<p>{car.description.replace(/\__([^*]+)\__/g,"<b>$1</b>")}</p>
</div>
)})}
In this case {car.description} would be for example:
"The __Audi RS 6 quattro__, commonly referred to as __the RS6__"
And I would like it to show up as:
"The Audi RS 6 quattro, commonly referred to as the RS6"
EDIT:
With this
<p>{car.description.replace(/\__([^*]+)\__/g,"<b>$1</b>")}</p>
I get back a string:
"The <b>Audi RS 6 quattro</b>, ..."
But how do I make JSX recognise to show it as bold, and not with the
tags on the frontend?
<p>{car.description.replace(/\__([^*]+)\__/g,"<b>$1</b>")}</p>