regex negative lookbehind assertion not working correctly?

G

Gabriel Rossetti

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
this:
"/profile.php?id=14522XXX98").groups()
('14522XXX9',)

which should not match, but it does, then I tried this :
"/profile.php?id=14522XXX99").groups()
('14522XXX99',)

which should match and it does. I then tried uring /positive lookbehind
assertion/ instead and it does this :
"/profile.php?id=14522XXX98").groups()
('14522XXX98',)

which matches as it should and then I tried this :
"/profile.php?id=14522XXX99").groups()
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,
Gabriel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top