Reputation: 2525
A complicated syntax like:
Model.objects.filter(url__iregex=r'^\S+\/\d+\/\S+$')
does not work. But something where I leave parts of the string that should be escaped, unescaped does returns elements:
Model.objects.filter(url__iregex=r'^http://www.c')
What am I doing wrong, or is regex not supported with MySQL in Django?
Upvotes: 1
Views: 518
Reputation: 627302
You need to use the MySQL REGEXP syntax for the expression:
^[^[:space:]]+/[0-9]+/[^[:space:]]+$
where
^
- start of string[^[:space:]]+
- 1 or more characters other than whitespace/
- a /
symbol[0-9]+
- 1 or more digits/
- a /
[^[:space:]]+
- 1 or more characters other than whitespace$
- end of string.Upvotes: 2