[Python-ideas] An iterable version of find/index for strings?
Steven D'Aprano
steve at pearwood.info
Tue Apr 9 01:52:39 CEST 2013
On 09/04/13 01:23, Stephen J. Turnbull wrote:
> 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,
I'm not Dutch, but I cannot imagine that:
import re
prefix = re.escape(prefix)
re.match(prefix, mystring)
should be considered more obvious than
mystring.startswith(prefix)
Oh, and just to demonstrate the non-obviousness of re.match, you don't
need to anchor the regex to the beginning of the string with ^ since
match automatically matches only at the start.
> and a
> potential benefit in encouraging people to avail themselves of the
> power of regexp search and matching.
The difficulty is not encouraging people to use regexes when they need
them. The difficulty is teaching people not to turn to regexes as the
first and only tool for solving every string-based problem.
--
Steven
More information about the Python-ideas
mailing list