in reply to How Do I Skip Spaces At The End of Words Using A Regex?

In addition to using quotemeta or \Q...\E, the g should be removed.

Furthermore, /\Q$y\E\s+/i is the same as /\Q$y\E\s/i (because of the lack of anchors and captures), and /\Q$y\E/i would surely suffice in this case.

Lastly, if ($x =~ /\Q$y\E/i) is slower than if (index(lc($x), lc($y)) >= 0).

Replies are listed 'Best First'.
Re^2: How Do I Skip Spaces At The End of Words Using A Regex?
by jwkrahn (Abbot) on Sep 18, 2006 at 08:36 UTC
    It may be slower in some circumstances.    :-)
    $ perl -le' my $x = "set manager logport [<0-10000>] set manager secondary ip A.B.C.D set mgmtport auto set mgmtport speed (10|100) duplex (full|half) set portsettletime <0-300> set sensor gateway A.B.C.D set sensor ip A.B.C.D E.F.G.H"; my $y = q/set mgmtport speed (10|100) duplex (full|half)/; use Benchmark q/cmpthese/; cmpthese -10, { regex => q[my $z = 1 if $x =~ /\Q$y\E\s/i], index => q +[my $z = 1 if index( lc $x, lc $y ) >= 0] }; ' Rate index regex index 1475956/s -- -24% regex 1932798/s 31% --
    Update: The regex gets even faster if you use the /o option.
    Rate index regex index 1431366/s -- -33% regex 2139276/s 49% --
Re^2: How Do I Skip Spaces At The End of Words Using A Regex?
by Not_a_Number (Prior) on Sep 18, 2006 at 08:27 UTC
    /\Q$y\E/i would surely suffice in this case

    In which case, /\Q$y/i would suffice :)