How to create a Case-Insensitive regex in eve rest framework

980 views Asked by At

I am using EVE REST Framework and POSTMAN

In my web API the search for a particular value takes place only when the exact match for the field value is given. It is case sensitive I would like make case insensitive search so that i could retrieve all the values matching the search criteria even if the search term is not given fully.

'url': 'regex("[\w]+")',

If I type just a or A I want all the values that start with a and A to be fetched.

Thanks in advance...

2

There are 2 answers

1
Nicola Iarocci On BEST ANSWER

A query example would be:

/?where={"field":{"$regex":"^(?i)value.*"} }

This would find all documents where field has values starting with "value", case insensitive ("Value", "value", "VALUE", etc.)

Remember though, by default $regex is blacklisted in Eve (MONGO_QUERY_BLACKLIST = ['$where', '$regex']). So if you really want it enabled, you also have to add this line to you settings.py:

MONGO_QUERY_BLACKLIST = ['$where']
0
Nizam Mohamed On

(?i)a.* matches both 'apple' and 'Apple'.
(?i) makes the following regex case insensitive.
Appending also works as in a.*(?i)