I actually gave a lightening talk on "How not to abuse regular expressions" at YAPC::Europe 2000. A couple of months later japhy posted Code Smarter which also touches on some of the ideas I mentioned. I had a list of common regexp idioms that are far more efficient when recast as substr, index and so on, I should see if I still have my notes lying around.
There are also a couple of paradoxical things to be aware of with regexps. It may seem that s/^\s+|\s+$/g should be faster than s/^\s+//; s/\s+$//. But it's nearly always not. The reason is that in the former case, the string has to be scanned in its entirety. In the latter case, only the beginning and end of the string need to be examined. The longer the string, the bigger the win.
In reply to Re: Seduced by a Regex
by grinder
in thread Seduced by a Regex
by kelan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |