I am trying to write a Django request that will match whole words. Based on the answer here , I tried something like:
result = Model.objects.filter(text__iregex='\bsomeWord\b')
But this does not return the expected result. I also tried
result = Model.objects.filter(text__iregex=r'\bsomeWord\b')
to no avail. My ultimate goal is to be able to pass a string variable, for example:
result = Model.objects.filter(text__iregex=r'\b'+stringVariable+r'\b')
or
result = Model.objects.filter(text__iregex=r'\b %s \b'%stringVariable)
But now I canβt even get it to work with a raw string. I am using PostgreSQL.
django regex postgresql django-queryset
Gchorn
source share