startswith() and endswith() for re's would be more intuitive

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Thu Sep 28 20:16:54 EDT 2006


In message <1159479137.991732.135620 at k70g2000cwa.googlegroups.com>, metaperl
wrote:

> There is also nothing wrong with
> 
> re.match('blah', somestring)
> 
> but it does read as well as
> 
> re.atstartof('blah', something)
> 
> and the counterpart for EOS is not there.

The only reason for those special cases for simple string matching is
precisely because string matching is so simple and so limited. Whereas
regular expressions give you so much more power--you can match at the
start, at the end, somewhere in the middle, 3 characters from the end, and
myriads of other possibilities. All of these can be succinctly expressed in
the RE notation itself, so there's no need for lots of special-case calls.



More information about the Python-list mailing list