Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Removing extra spaces

by NetWallah (Abbot)
on Jul 31, 2012 at 01:28 UTC ( #984545=note: print w/ replies, xml ) Need Help??


in reply to Removing extra spaces

Try this regex:

s/\s\s?(\S)/$1/g
Update: See the correction below. Thanks Anonymonk and davido.

             I hope life isn't a big joke, because I don't get it.
                   -SNL


Comment on Re: Removing extra spaces
Download Code
Replies are listed 'Best First'.
Re^2: Removing extra spaces
by Anonymous Monk on Jul 31, 2012 at 06:42 UTC

    Close, just drop the \s? and it works.

    $ perl -E '$s="2 0 1 2 - 7 - 2 7 9 : 3 7 : 3 1"; $s =~ s/\s\s?(\S)/$1 +/g; say $s' 2012-7-279:37:31 $ perl -E '$s="2 0 1 2 - 7 - 2 7 9 : 3 7 : 3 1"; $s =~ s/\s(\S)/$1/g; + say $s' 2012-7-27 9:37:31

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2015-07-08 02:56 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