Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django filter with regex

I want to write regex for django's model's charField. That regex contains all letters and last character contains "/".

Eg: "sequences/"

I return regex as follows,

Model.objects.filter(location_path__iregex=r'^[a-zA-Z]/$')

It is not showing filter data. demo data for location_path is ['sequences/', 'abc/xyz/', 'abc/aaaa/aaa', 'pqr/']

I want to filter data like 'sequences/', 'pqr/' which contains any character from a-z and field end with '/'

Please give me the proper regex pattern and syntax

like image 300
Mugdha Avatar asked Sep 12 '14 08:09

Mugdha


1 Answers

You need to add + after the character class, so that it would match one or more letters,

r'^[a-zA-Z]+/$'
like image 159
Avinash Raj Avatar answered Oct 14 '22 03:10

Avinash Raj