in reply to regex internals: quantifiers vs global match
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; ...
|
|---|