|
|||
|
Gabriel Rossetti wrote:
> 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: > > >>> re.search(r"/profile.php\?id=(\d+)(?<!14522XXX98)", > "/profile.php?id=14522XXX98").groups() > ('14522XXX9',) > > which should not match, but it does, then I tried this : > [snip] How can '(\d+)' be capturing '14522XXX9'? '\d' matches only digits! Anyway, your basic problem is that it initially matches '14522XXX98', but then the lookbehind rejects that, so it backtracks and releases the last character, giving '14522XXX9', which is not be rejected because '14522XXX9' isn't '14522XXX98'. Try putting a '\b' after the '\d+' to reject partial IDs. |
|
|
||||
|
||||
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: regex negative lookbehind assertion not working correctly? | Gabriel Rossetti | Newsgroup comp.lang.python | 0 | 03-31-2009 07:13 PM |
| Re: regex negative lookbehind assertion not working correctly? | andrew cooke | Newsgroup comp.lang.python | 0 | 03-31-2009 03:52 PM |
| regex negative lookbehind assertion not working correctly? | Gabriel Rossetti | Newsgroup comp.lang.python | 0 | 03-31-2009 03:38 PM |
| Proc Report: 'group descending' not working for negative numbers | Matt Pettis | Newsgroup comp.soft-sys.sas | 1 | 10-14-2007 04:21 PM |
| Re: Proc Report: 'group descending' not working for negative | Matt Pettis | Newsgroup comp.soft-sys.sas | 0 | 10-12-2007 09:25 PM |