I have the following JavaScript code
function strong(){
var element = document.getElementById("deco");
var value = element.textContent || "";
var regex = /\*([a-zA-Z\d\w\s]+)\*/gi; // STRONG
value = value.replace(regex, "<strong>$1</strong>"); // STRONG
element.innerHTML = value;
} strong();
<p id="deco">
*Lorem Ipsum* is simply dummy text of the printing and typesetting industry. *¿Lorem Ipsum, has beén?* the industry's standard dummy text ever since the *¡1500s!*
</p>
The sentences that are enclosed in asterisks become strong, the problem, as you can see, is that it does not work if it has ( commas, accents, expression symbols, etc... ) I have tried adding these characters to the regular expression, but it does not work.
I appreciate your comments and responses.
Depending on the rules you want to put in, using a regular expression for what you want to do can get very complicated: Do you want to accept "escaped" asterisks to make them bold? :
*en negrita \* con asterisco*
-> in bold * with asterisk .If you want a simpler version, you can use a regular expression that catches everything that is n't an asterisk: