Blog of Leonid Mamchenkov

You just stepped in a pile of posts.

Entries Tagged as 'regular-expression'

RegExp reminder

Posted in All on February 22nd, 2006 · No Comments

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.

→ No CommentsTags: , , , , , ,