Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100720

match point

Date 2015-12-22 11:56 +0100
From Thierry <no@mail.com>
Newsgroups comp.lang.python
Subject match point
Message-ID <20151222115648.1222c992@eeearch> (permalink)
Organization Guest of ProXad - France

Show all headers | View raw


Hi,

Reading the docs about regular expressions, I am under the impression
that calling
	re.match(pattern, string)
is exactly the same as
	re.search(r'\A'+pattern, string)

Same for fullmatch, that amounts to
	re.search(r'\A'+pattern+r'\Z', string)

The docs devote a chapter to "6.2.5.3. search() vs. match()", but they
only discuss how match() is different from search() with '^', completely
eluding the case of search() with r'\A'.

At first I thought those functions could have been introduced at a time
when r'\A' and r'\Z' did not exist, but then I noticed that re.fullmatch
is a recent addition (python 3.4)

Surely the python devs are not cluttering the interface of the re module
with useless functions for no reason, so what am I missing?

Maybe re.match has an implementation that makes it more efficient? But
then why would I ever use r'\A', since that anchor makes a pattern match
in only a single position, and is therefore useless in functions like
re.findall, re.finditer or re.split?

Thanks,

Thierry

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

match point Thierry <no@mail.com> - 2015-12-22 11:56 +0100
  Re: match point Chris Angelico <rosuav@gmail.com> - 2015-12-22 22:07 +1100
  Re: match point Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-12-22 13:01 +0100
  Re: match point Thierry Closen <no@mail.com> - 2015-12-22 18:18 +0100

csiph-web