in reply to Regex operation optimisation

- remove special characters like (% ,(,),*)
$string =~ tr/%()*//d;
- replace continuous white spaces with a single underscore
$string =~ tr/ /_/s;

Replies are listed 'Best First'.
Re^2: Regex operation optimisation
by marinersk (Priest) on Jul 02, 2010 at 21:39 UTC

      perlpal's example was $string =~ s/ {1,}/_/g; which matches a space character while your example $string =~ s/\s+/\_/g; uses the whitespace character class (\s) which matches "\t", "\r", "\n" and "\f" as well as the space character.    In general, the tr/// operator is more efficient then the s/// operator so I try to use it when appropriate.

        Thank you!

        I was right, this WAS an opportunity for me to learn something.

        :: giggle ::

        Love days like that.