Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python django partial match regular expression

So i want to filter a queryset and get all objects that have a partial match to a word

queryset.filter(name=r'regex')

search term = app

  • apple = true
  • application = true
  • aptitude = false
  • stuff = false
  • pineapple = true

I am really bad with regex any help would be greatly appreciated.

like image 305
mingle Avatar asked Sep 03 '25 05:09

mingle


1 Answers

You don't need a regex for a partial match, use contains:

queryset.filter(name__contains='partial')

Or when you need a case-insensitive match:

queryset.filter(name__icontains='partial')
like image 95
knbk Avatar answered Sep 04 '25 17:09

knbk