in reply to japhy blabs about regexes (again)

I've been using s/[ ]+//g; which seems to work effectively on all the varied spacing it's run into. Sticking it into runrigs Bench test as CURIOUS it yields:

Benchmark: running CURIOUS, LEADING, LEADTRAIL, LTSAVE, SEXEGER, SINGL +E_RE, WHILE_RE, each for at least 5 CPU seconds... CURIOUS: 6 wallclock secs ( 5.42 usr + 0.00 sys = 5.42 CPU) @ 39 +780.44/s (n=215610) LEADING: 6 wallclock secs ( 5.29 usr + 0.00 sys = 5.29 CPU) @ 68 +400.00/s (n=361836) LEADTRAIL: 6 wallclock secs ( 5.21 usr + 0.00 sys = 5.21 CPU) @ 28 +325.53/s (n=147576) LTSAVE: 6 wallclock secs ( 5.32 usr + 0.00 sys = 5.32 CPU) @ 30 +798.68/s (n=163849) SEXEGER: 5 wallclock secs ( 5.28 usr + 0.00 sys = 5.28 CPU) @ 50 +426.89/s (n=266254) SINGLE_RE: 6 wallclock secs ( 5.31 usr + 0.00 sys = 5.31 CPU) @ 54 +235.40/s (n=287990) WHILE_RE: 7 wallclock secs ( 5.47 usr + 0.00 sys = 5.47 CPU) @ 34 +396.53/s (n=188149)
coreolyn

Replies are listed 'Best First'.
Re: Re: japhy blabs about regexes (again)
by Hofmator (Curate) on Jul 17, 2001 at 19:54 UTC

    Mmmhh, you are removing all the spaces from the string, this was not the original question. It was about removing whitespace (which includes \t, \r, \n, \f and your space) from the start and end of a string.

    btw, you are using a character class in your regex where it is not necessary, so just write: s/ +//g; and for this task a regex is overkill, use a transliteration (tr) instead: tr/ //d;

    -- Hofmator

      I figured I wasn't quite getting it, but stuck my nose out there anyway. What's that saying about curiousity? :)

      coreolyn