Discussion:
Pattern help!?
Lennart Regebro
2010-11-18 11:49:22 UTC
Permalink
I can't find a pattern that will match:
foo
But not
bar.foo

Any hints?

//Lennart
M.-A. Lemburg
2010-11-18 12:48:25 UTC
Permalink
Post by Lennart Regebro
foo
But not
bar.foo
Any hints?
Hi Lennart,

you can use a negative lookahead:

(?!bar\.)foo
--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Nov 18 2010)
Post by Lennart Regebro
Python/Zope Consulting and Support ... http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
Lennart Regebro
2010-11-18 13:29:59 UTC
Permalink
Post by M.-A. Lemburg
(?!bar\.)foo
Ah, sorry for wasting peoples time by not including enough context. My bad.

I'm looking for a patterns for making a fixer, not a regexp. :-)
Fred Drake
2010-11-18 14:08:24 UTC
Permalink
Post by M.-A. Lemburg
(?!bar\.)foo
This is normally called a negative lookbehind, though.


  -Fred

--
Fred L. Drake, Jr.    <fdrake at acm.org>
"A storm broke loose in my mind."  --Albert Einstein
Georg Brandl
2010-11-18 14:33:17 UTC
Permalink
Post by Fred Drake
Post by M.-A. Lemburg
(?!bar\.)foo
This is normally called a negative lookbehind, though.
Both are slightly wrong: what Marc gave is a lookahead, but
ISTM he *should* have given a lookbehind :)

Georg
Fred Drake
2010-11-18 14:53:01 UTC
Permalink
Post by Georg Brandl
Both are slightly wrong: what Marc gave is a lookahead, but
ISTM he *should* have given a lookbehind :)
Which shows how often I don't use either. :-) Sorry for the
misinformation, Lennart!


  -Fred

--
Fred L. Drake, Jr.    <fdrake at acm.org>
"A storm broke loose in my mind."  --Albert Einstein
Lennart Regebro
2010-11-18 16:29:30 UTC
Permalink
Post by Georg Brandl
Both are slightly wrong: what Marc gave is a lookahead, but
ISTM he *should* have given a lookbehind :)
Which shows how often I don't use either.  :-)  Sorry for the
misinformation, Lennart!
This feels like a good example of why I avoid regexps. :-)

//Lennart

Benjamin Peterson
2010-11-18 14:00:21 UTC
Permalink
   foo
But not
   bar.foo
Any hints?
It's usually best to do something like "is_probably_builtin" in
lib2to3/fixer_utils.py.
--
Regards,
Benjamin
Lennart Regebro
2010-11-18 14:03:21 UTC
Permalink
Post by Benjamin Peterson
   foo
But not
   bar.foo
Any hints?
It's usually best to do something like "is_probably_builtin" in
lib2to3/fixer_utils.py.
Ah, thanks! That's similar to what I did already, but I missed out on
this helper (as it's slightly weirdly named), and this one catches
several cases I didn't think of.

//Lennart
Loading...