1) Searching for the asterisks: \*([^\*]+?)\*(?!\*)
2) Adding tags to bold: <strong>$2</strong>
Now just apply in your project:
let str = 'Lorem *ipsum dolor* sit amet, *consectetur** adipisicing elit. Optio repellat ipsa quibusdam ab doloremque accusamus nobis minima maiores voluptas, incidunt rerum alias, aliquam ut minus consequatur odio voluptatibus voluptates exercitationem.';
str = str.replace(/\*([^\*]+?)\*(?!\*)/i, '<strong>$1</strong>');
console.log(str);
@Edit Now it won’t find if you have two asterisks together, with nothing inside.
@edit2 Now it won’t find if you have two asterisks together at the end of the search expression, as recalled @sam (*expressão**
). And I improved upon the suggestion of @hkotsubo.
Working example: Regex101.com
Another possible: Create markup with predefined symbols
– Woss