Skip to content
Advertisement

Regex bold characters using *

If I have text like:

I need to bold *this* text and *that* text.

I need to bold this text and that text.

I need to convert both to <b>this</b> and <b>that</b>.

JavaScript

This is not doing what I want for 2 or more matches. It’s doing this instead:

I need to bold this text and that text and this text and that text.

Advertisement

Answer

You can just use a capture group and a group reference number :

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement