http://www.perlmonks.org?node_id=161539


in reply to How to bold text with regexp...

Simplest way is:

$text =~ s/\*([^*]+)\*/<em>$1<\/em>/g;
That starts at any given asterisk and selects till the next.

stephen

Replies are listed 'Best First'.
Re: Re: How to bold text with regexp...
by thelenm (Vicar) on Apr 24, 2002 at 14:58 UTC
    If I understand the question, we should only change asterisks at the beginning and end of a word, rather than all asterisks two at a time... if that's the case, you might want something more like:
    $text =~ s/\b\*([^*\s]+)\*\b/<em>$1<\/em>/g;
    which will only replace pairs of asterisks at beginning and ending word boundaries, where there are no space characters between the asterisks. I'm not sure if that's what the original poster meant, though.