Skip to content


RegExp reminder

I was just reminded about this small thing, which is so easy to forget – regular expressions that have markers of line start (^) and/or line end($) are so much faster than those regexps that don’t have these markers. The thing is that with line start/end marker regexp engine needs to make only one match/substution, whereas when there is no such markers, it has to repeat the match/substitution operation at every character of the string.

In practice, it’s unbelievable how much difference this can make. Especially when using complex regular expressions over large data sets.

P.S.: I understand that it is not always possible to use these markers, but I think that they can be used much more often than they are. Everywhere.

Posted in All, Programming.

Tagged with , , , , .

See also: Profiling perl, Portability and flexibility win over performance, InnoDB is better for SugarCRM, Decimal to binary convertion in Perl, Zip vs. Bzip2.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.



Rss Feed Tweeter button Facebook button Reddit button Linkedin button Delicious button Digg button Flickr button Stumbleupon button Youtube button