Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Using a regular expression.

by roju (Friar)
on Jul 14, 2003 at 17:06 UTC ( #274051=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    s/         #replace
    ^[\s]*     #the start of the string followed by any number of spaces
    ...
    (?<!\s)    #look-behind assertion to get to the last non-whitespace ch
    +ar
    \s*$       #match whitespace until EOL
    /$1/x;     #replace with the (.*)
    
  2. or download this
    Benchmark: timing 100000 iterations of my_long_one, one_liner, two_lin
    +er...
    my_long_one:  6 wallclock secs ( 4.62 usr +  0.00 sys =  4.62 CPU) @ 2
    +1659.09/s (n=100000)
    one_liner:  3 wallclock secs ( 3.89 usr +  0.00 sys =  3.89 CPU) @ 256
    +73.94/s (n=100000)
    ...
    my_long_one => s/^[\s]*(.*)(?<!\s)\s*$/$1/
    one_liner => s/^\s+|\s+$//g
    two_liner => s/^\s+//g; s/s+$//g
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2020-04-10 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (49 votes). Check out past polls.

    Notices?