It really depends on your input...

Anoter alternative for your regex would be: tr/x//d; (but ofcourse this only works when you want to remove some charachters and not a word).

What I noticed during benchmarking is that the less x's follows eachother the faster tr/// gets (or the slower s/// gets). Below you find the benchmarks I ran:

String: 'a' . ('x' x 1000) . 'b':

Rate NoPlus Tr Plus NoPlus 2465/s -- -97% -98% Tr 94056/s 3715% -- -15% Plus 111285/s 4414% 18% --

String: 'a' . ('x' x 100) . 'b':

Rate NoPlus Plus Tr NoPlus 22929/s -- -91% -93% Plus 245996/s 973% -- -25% Tr 328951/s 1335% 34% --

String: 'ax' x 1000:

Rate NoPlus Plus Tr NoPlus 2224/s -- -6% -95% Plus 2367/s 6% -- -95% Tr 49416/s 2122% 1988% --

String: 'ax' x 100:

Rate NoPlus Plus Tr NoPlus 21151/s -- -4% -93% Plus 22038/s 4% -- -93% Tr 302771/s 1331% 1274% --

Based on these results I would most likely use tr/x//d; ...


In reply to Re: regex internals: quantifiers vs global match by Animator
in thread regex internals: quantifiers vs global match by davidrw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.