Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Replacing whitespaces with a regex

by ggoebel (Sexton)
on Mar 04, 2013 at 13:51 UTC ( #1021643=note: print w/ replies, xml ) Need Help??


in reply to Replacing whitespaces with a regex

When you have the time read perlre

If you're in a rush... skip down to the section on "Quantifiers". TIMTOWTDI. Pick the way which you think you'll stand the best chance of understanding 3 weeks or 3 months from now when you're asked to tweak your code.

Both:

$work =~ s/\s+$/ /; # more than once

and

$work =~ s/\s{2,}$/ /; # at least twice

should work.


Comment on Re: Replacing whitespaces with a regex
Select or Download Code
Re^2: Replacing whitespaces with a regex
by soonix (Priest) on Mar 04, 2013 at 14:16 UTC

    that should read "once or more" instead of "more than once"

    ++ anyway :-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2015-07-02 06:24 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 (30 votes), past polls