Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: How to bold text with regexp...

by stephen (Priest)
on Apr 24, 2002 at 08:40 UTC ( #161539=note: print w/ replies, xml ) Need Help??

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.


Comment on Re: How to bold text with regexp...
Download Code
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://161539]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2015-12-01 09:57 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (798 votes), past polls