Why re.match()?

Carl Banks pavlovevidence at gmail.com
Wed Jul 1 18:33:01 EDT 2009


On Jul 1, 10:56 am, kj <no.em... at please.post> wrote:
> For a recovering Perl-head like me it is difficult to understand
> why Python's re module offers both match and search.  Why not just
> use search with a beginning-of-string anchor?  I find it particularly
> puzzling because I have this (possibly mistaken) idea that the
> Python design philosophy tends towards minimalism, a sort of Occam's
> razor, when it comes to language entities; i.e. having re.match
> along with re.search seems to me like an "unnecessary multiplication
> of entities".  What am I missing?

It always seemed redundant to me also (notwithstanding Duncan Booth's
explanation of slight semantic differences).  However, I find myself
using re.match much more often than re.search, so perhaps in this case
a "second obvious way" is justified.


Carl Banks



More information about the Python-list mailing list