问题
I'm trying to perform a regex query with cloudant and can't figure out how to do a case and accent insensitive query.
I've tried the following (for case insensitive): ^.*((?i)<needle>).*$
but it doesn't work.
For the accents (french), I don't even know how to start...
回答1:
To do a case insensitive query just add the caseless
option when invoking re:run/3 or re:compile/2, e.g.:
18> re:run(<<"abCd">>, <<"c">>, [caseless]).
{match,[{2,1}]}
I am not sure if accent insensitive queries are supported, but you can try to specify alternative letters using []
, e.g.:
12> re:run(<<"abęxo"/utf8>>, <<"[eę]"/utf8>>).
{match,[{2,1}]}
13> re:run(<<"abexo"/utf8>>, <<"[eę]"/utf8>>).
{match,[{2,1}]}
If that's not enough then you may need to check the Unicode support in Erlang and in re in particular to see if what you want to achieve is supported.
来源:https://stackoverflow.com/questions/35546549/query-case-and-accent-insensitive