[Yum-devel] [PATCH 1/3] Simplify some regexps.

Ville Skyttä ville.skytta at iki.fi
Wed Oct 28 19:05:58 UTC 2009

On Wednesday 28 October 2009, James Antill wrote:
> On Wed, 2009-10-28 at 19:06 +0200, Ville Skyttä wrote:
> > ---
> >  yum/misc.py    |    8 ++++----
> >  yum/yumRepo.py |    4 ++--
> >  2 files changed, 6 insertions(+), 6 deletions(-)
>  Does removing the ^ from the regexp make any difference? Coming from a
> perl/grep background I always expect that they are needed, so removing
> them is likely to confuse ... esp. as sub/search don't have the retarded
> behaviour of match.

Based on http://docs.python.org/library/re.html#matching-vs-searching and my 
experience with Python regexps I don't think there's any case where a ^ would 
make a difference with re.match() - it always succeeds only at start of a 
string, ^ or not, re.MULTILINE or not.  re.search() with ^ on the other hand 
matches start of lines in re.MULTILINE mode in addition to start of strings.

I too have a Perl/grep (and Java, Lisp) background, and I have never 
understood why re.match() even exists in the first place... but *shrug*

> > -    if re.match('.*[\*,\[,\],\{,\},\?,\+].*', arg):
> > +    if re.search('[*[\]{}?+]', arg):
> >          restring = fnmatch.translate(arg)
> >      else:
> >          restring = re.escape(arg)
>  I always assumed the commas were a typo, or brain fart or something,
> and AKAICS there are no provides have have a comma in them ... but one
> reason I never did anything is that a comma would take a different
> branch now and AFAIK there are no callers of refineSearchPattern.

Exactly my thoughts (except that I went ahead and removed it anyway ;)).  I 
intended to post a followup after the patch to explain some changes including 
this one but got distracted, sorry.  But you got it anyway, cool.

More information about the Yum-devel mailing list