mats cronqvist: >> This is faster than your code for the situations I tested, but still >> much slower than the regexp module: > > please don't use, or even mention, the regexp module. it makes my > brain hurt. re is what you want. My bad. I used the word "regexp" as short for "regular expression". I forgot there's still a module called that.