带正则表达式的Django过滤器 [英] Django filter with regex
问题描述
例如:sequences /
I返回正则表达式如下,
Model.objects.filter(location_path__iregex = r'^ [a-zA-Z] / $' )
它不显示过滤数据。
location_path的演示数据是['sequences /','abc / xyz /','abc / aaaa / aaa','pqr /']
我想过滤像'sequences /','pqr /'这样的数据,其中包含来自az和field的任何字符'/'
请给我正确的正则表达式和语法
您需要在字符类后添加 +
以便它匹配一个或多个字母,
r'^ [a-zA-Z] + / $'
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
You need to add +
after the character class, so that it would match one or more letters,
r'^[a-zA-Z]+/$'
这篇关于带正则表达式的Django过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!