in reply to Seduced by a Regex
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Seduced by a Regex
by kelan (Deacon) on Sep 30, 2002 at 16:45 UTC | |
|
Re: Re: Seduced by a Regex
by Sihal (Pilgrim) on Oct 01, 2002 at 08:28 UTC |