Saturday, December 1st, 2007 •
Related •
Filed Under
A common misconception about regular expression performance is that lazy quantifiers (also called non-greedy, reluctant, minimal, or ungreedy) are faster than their greedy equivalents. That's generally not true, but with an important qualifier: in practice, lazy quantifiers often are faster. This seeming contradiction is due to the fact that many people rely on backtracking to [...]
Read More
Thursday, October 4th, 2007 •
Related •
Filed Under
Crafting efficient regular expressions is somewhat of an art. In large part, it centers around controlling/minimizing backtracking and the number of steps it takes the regex engine to match or fail, but the fact that most engines implement different sets of internal optimizations (which can either make certain operations faster, or avoid work by performing [...]
Read More
Thursday, June 7th, 2007 •
Related •
Filed Under
Since JavaScript doesn't include a trim method natively, it's included by countless JavaScript libraries – usually as a global function or appended to String.prototype. However, I've never seen an implementation which performs as well as it could, probably because most programmers don't deeply understand or care about regex efficiency issues.
After seeing a particularly bad trim [...]
Read More
Sunday, February 4th, 2007 •
Related •
Filed Under
I near-religiously use non-capturing groups whenever I do not need to reference a group's contents. Recently, several people have asked me why this is, so here are the reasons:
Capturing groups negatively impact performance. The performance hit may be tiny, especially when working with small strings, but it's there.
When you need to use several groupings in [...]
Read More