Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > regex negative lookbehind assertion not working correctly?

Thread Tools

regex negative lookbehind assertion not working correctly?

Gabriel Rossetti
Posts: n/a
Hello everyone,

I am trying to write a regex pattern to match an ID in a URL only if it
is not a given ID. Here's an example, the ID not to match is
"14522XXX98", if my URL is "/profile.php?id=14522XXX99" I want it to
match and if it's "/profile.php?id=14522XXX98" I want it not to. I tried



which should not match, but it does, then I tried this :



which should match and it does. I then tried uring /positive lookbehind
assertion/ instead and it does this :



which matches as it should and then I tried this :


Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'groups'

which doesn't match as it should. Could someone please explain why the
negative lookbehind assertion is not working as I understand it? Also,
notice how the last digit of the first expression is not matched, I get
('14522XXX9',) instead of ('14522XXX98',), why? It does on the others....

Thank you,
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
A zero-width positive lookbehind assertion George Perl Misc 4 02-06-2010 11:30 PM
Re: regex negative lookbehind assertion not working correctly? MRAB Python 0 03-31-2009 05:08 PM
Re: Confused about 'positive lookbehind assertion' Erik Jones Python 3 09-26-2007 10:02 AM
Negative Lookbehind Replacement? mail Perl 1 03-02-2004 03:14 PM
Negative Lookbehind and Wildcards Thomas F. O'Connell Perl 1 02-28-2004 01:50 PM