From the database, we get the string in the following format.
_This is string from DB_. Make sure this is format from DB
Now, on JSX/javascript, I want to set the string between two underscores to bold (this is the string from the database in bold format)
P粉5739437552023-09-16 00:28:10
You can use a regular expression to match a string between two underscores and wrap it with a label. You can do this using the string object's replace method. For example, you can modify the code like this:
const dbString = "_This is string from DB_. Make sure this is format from DB"; const formattedString = dbString.replace(/_(.*?)_/g, "<b></b>"); return <div dangerouslySetInnerHTML={{ __html: formattedString }} />;