On Monday 19 June 2017 16:43:12 James Schneider wrote:
> But if I use the pattern:
>
> *urlpatterns = [ *
> * url(r'^blank/.*$', views.BlankMore, name='blankMore'),*
> *]*
>
> I can enter:
>
> localhost:8000/uA/blank/
>
> and the pattern will match, but if I enter:
>
> localhost:8000/uA/blank/abc
>
> I get an error message: "Page not found (404)"
>
> I could be doing something wrong here, however I am more inclined to
> believe this is a bug. My error? Bug?
>
>
> This appears to be working as designed. Your interpretation of the
> regex algorithm behavior is incorrect. In most cases, the matching
> algorithm will take the first and almost always shortest match (there
> are probably some exceptions nestled deep in the Python re module).
What did you base this on? Certainly not the python docs or behavior of any pcre based library.
Regular expressions are capitalist: greedy by default.
The qualifiers *? are there especially to make a match non-greedy.
Quick test:
pcregrep -o '^.*:' /etc/passwd
versus:
pcregrep -o '^.*?:' /etc/passwd
> The .* modifier means "match any character (.) zero or more times
> (*)". Since blank/ matches the .* zero times, it is a match for your
> expression.
And his problem is that it does *not* match. Not that it does.
--
Melvyn Sopacua
No comments:
Post a Comment