[Python-ideas] An iterable version of find/index for strings?

Stephen J. Turnbull stephen at xemacs.org
Mon Apr 8 17:23:58 CEST 2013


Andrew Barnert writes:

 > Yes, but regular expressions shouldn't be the one way to do a
 > simple text search!

Why not?  I don't see a real loss to "match('^start')" vs
"startswith('start')" in terms of difficulty of learning, and a
potential benefit in encouraging people to avail themselves of the
power of regexp search and matching.

As far as efficiency goes, XEmacs does the simple thing and checks
each alleged regexp for metacharacters, and if there aren't any, falls
back to Boyer-Moore.  Whoosh!

It would not be hard to add similar peephole optimizations for
searches or matches that would be most efficiently implemented with
startswith, endswith, find, index, etc.

Of course, we would need to check how often people search for
punctuation (or strings including punctuation).  But my suspicion is
that people who don't want to grok the most basic features of regexps
probably don't search for "\.\*" or the like very often.  They
probably stick to alphanumerics anyway.




More information about the Python-ideas mailing list