From DB, we are getting string in following format.
_This is string from DB_. Make sure this is format from DB
Now, on JSX/javascript, I want to make string between two underscores as bold (This is string from DB to be bold format)
>Solution :
You can use a regular expression to match the string between two underscores, and wrap it with a tag. You can use the replace method of the string object to perform this operation. For example, you can modify your code like this:
const dbString = "_This is string from DB_. Make sure this is format from DB";
const formattedString = dbString.replace(/_(.*?)_/g, "<b>$1</b>");
return <div dangerouslySetInnerHTML={{ __html: formattedString }} />;