Improve filter regex
Created by: rostixman
What would you like to be able to do? Can you provide some examples?
I would like to be able to pass filter attribute in French, German, or other languages. Because now regex doesn't allow non-Latin characters.
In my case I have Mobility gem and want to search in other languages. I found solution with custom search method, but in my case it's enough to add this:
COLLECTION_FILTERS = {
name: -> (resources, attr) { resources.search(attr) }
}.freeze
and also I add search method to resource model with the logic that I need:
scope :search, -> (name_q) do
i18n do
name.lower.matches("%#{name_q&.downcase}%")
end
end
How could we go about implementing that?
Switch \w to Unicode codes/ranges or word.match?(/^#{filter}:.*$/)
but this way may be unsafe
Can you think of other approaches to the problem? Allow custom regex for filter attribute