Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.python

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-31-2009, 05:08 PM
MRAB
Guest
 
Posts: n/a
Default Re: regex negative lookbehind assertion not working correctly?

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.
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

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 Off
Pingbacks are Off
Refbacks are Off


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



All times are GMT. The time now is 09:20 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.