Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
No such thing as a small change
 
PerlMonks  

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.

stephen


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

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-04-16 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (434 votes), past polls