I was wondering if we could get regex support in SG API's filter, it would be super helpful to have.
3 comments
-
Nephi Sanchez Official comment Thanks for the request Mahendra!
Would you mind mocking up how this would look, maybe an example of how it would work? Would love to see some use cases as well where you would use this feature.
cheers,
Nephi -
Mahendra Gangaiwar Thanks Nephi for reverting back on this.
I felt it while doing task and delivery related operations where tasks names were following pattern like <string>_<digit>_<string>, Delivery<int> etc.. right now we have contains, not_contains, in, not_in, starts_with, ends_with in filter, and in most cases it would work, but when I need to fetch a big chuck without knowing its content to filter with using existing filter directives, but I know it follows some kind of pattern.
In above case, we have delivery schema setup at our end which is configurable as per shows requirement and follows regex matching as per linked entity for deriving its name, so in this case, as this schema can be as dynamic as possible, I couldn't able to lookup delivery name with same pattern, I had to break it down further as per schema to fetch the required delivery name, though I was able to put a logic for doing it in a different way, I got it working.
Simple mockup would be:
filters = ['title', 'matches', '[a-zA-Z]+[\d]']
results = sg.find('Delivery', [filters], [])
this should return all the deliveries which has which starts with characters and ends with one number.
filters = ['title', 'matches', r'{([^}]+)}']
this should return me all the deliveries in which non empty "{}" is found.
Hope this help understanding the request. Please let me know if you need more information.
PS: I'm not putting literal "{}" in title its a part of metadata information of entity, its just for mockup :)
Cheers,
-M
-
Nephi Sanchez Hi Mahendra,
Thanks for the additional color, very helpful!
cheers,
Nephi