Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Looking for white spaces between words

by bradcathey (Prior)
on Jun 10, 2004 at 20:47 UTC ( [id://363189]=note: print w/replies, xml ) Need Help??


in reply to Re: Looking for white spaces between words
in thread Looking for white spaces between words

That works great to replace all spaces. However, as a casual observer, I'm not sure this is what was asked. Were all the spaces to be replaced with the non-breaking spaces, or just those after the first one, leaving one space without the replacement. So:
"the lazy  brown   fox    jumped..."
But I would like to expand the question a bit. I would like to see all spaces removed with the exception of just one separating the words, and then have that replace with the non-breaking space. So:
"the lazy brown fox jumped..."

—Brad
"A little yeast leavens the whole dough."

Replies are listed 'Best First'.
Re^3: Looking for white spaces between words
by Enlil (Parson) on Jun 10, 2004 at 20:55 UTC
    That works great to replace all spaces. However, as a casual observer, I'm not sure this is what was asked. Were all the spaces to be replaced with the non-breaking spaces, or just those after the first one, leaving one space without the replacement. So:
    "the lazy  brown   fox    jumped..."

    This should work:

    $foo =~ s/(?<= )( +)/'&nbsp;' x length($1)/ge

    But I would like to expand the question a bit. I would like to see all spaces removed with the exception of just one separating the words, and then have that replace with the non-breaking space. So:

    "the lazy&nbsp;brown&nbsp;fox&nbsp;jumped..."

    Can be solved thusly:

    $foo =~ s/ {2,}/&nbsp;/g;
    I believe this answers both requests unless I am misreading something.

    -enlil

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-29 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found