Karen Tracey wrote:
> On Tue, Oct 6, 2009 at 1:32 PM, Mat <crash....@gmail.com> wrote:
> 
>> Okay so here is my code:
>>
>> ******This way works and does not error******
>> rs = BadActor.objects.filter(addr__iregex='^(192\.188\.)(.*)(\.20)$');
>> print len(rs);
>> print rs[0].addr
>>
>> *******This way errors********
>> q = Q({'addr__iregex':'^(192\.188\.)(.*)(\.20)$'});
>>
> 
> Why the dict?  Why not simply:
> 
> q = Q(addr__iregex='^(192\.188\.)(.*)(\.20)$')

You'll also want to use python's "raw" strings for regexps...this 
isn't the regexp you think it is.  You likely want

   r'^(192\.188\.)(.*)(\.20)$'

As your pattern was originally, the "\." bits get unescaped as 
just "." because there is no "\." escape-character.  It then 
becomes just "^(192.188.)(.*)(.20)$" and would match

   192Z188Xabcdefg920
   [......][.....][.] <- matched groups

which I don't think is what you meant.  And as one other aside, 
do you mean "192.168" (a popular private subnet block) instead of 
"192.188"?  Though this is just a matter of what you mean, and 
you may really mean "192.188"

-tim




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to