Reputation: 353
I am considering offering an OData
interface to my database. I need to allow regular expressions on string fields, i.e., in OData $filter
conditions.
OData offers substringof()
, startswith()
, and other functions, but I could not find anything about regular expressions in the docs.
Is this possible?
Such a regex function would probably look like:
/Customers?$filter=match(CompanyName, '^Al[a-z]+s Futterkiste') eq true
where match()
is a function that I just made up.
Upvotes: 2
Views: 8358
Reputation: 5275
The protocol doesn´t have any built-in regex operator for filtering. However you can achieve what you are looking for (or something similar) as follow:
GET http://server/Customers?$filter=match(CompanyName=$it/CompanyName, Regex='^Al[a-z]+s Futterkiste') eq true
In this case, you have to have a function 'match' which takes two paramentes: CompanyName and Regex. That function returns true/false depending on company name matches or not. Then, for each company, match function is invoked.
Of course the implementation depends on the server-side technology you are using.
You can read more here: http://www.odata.org/media/30002/OData.html#inlineparametersyntax
Good luck.
Upvotes: 1