Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: Regular Expressions: Removing 'only' single spaces from a string

by Trix606 (Monk)
on Oct 20, 2005 at 20:28 UTC ( #501803=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Regular Expressions: Removing 'only' single spaces from a string
in thread Regular Expressions: Removing 'only' single spaces from a string

I found that the following works on both sample strings:

$string =~ s/(\S)\s(\S)/$1$2/g;


Comment on Re^4: Regular Expressions: Removing 'only' single spaces from a string
Download Code
Replies are listed 'Best First'.
Re^5: Regular Expressions: Removing 'only' single spaces from a string
by Roy Johnson (Monsignor) on Oct 20, 2005 at 23:32 UTC
    Won't work for a single space at the beginning or end of the string. To fix:
    $string =~ s/(\S|^)\s(\S|$)/$1$2/g;
    But the lookahead solution is preferable.

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2015-07-07 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls