Query - Case and accent insensitive

≯℡__Kan透↙ 提交于 2020-01-07 03:49:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!