Set two flags in Java regex.Pattern

老子叫甜甜 提交于 2019-11-29 00:37:49

问题


I need a matcher like this:

Matcher kuchen = Pattern.compile("gibt es Kuchen in der K\u00FCche",Pattern.CASE_INSENSITIVE).matcher("");

and the problem is that it is not simple ASCII. I know that in this particular case I could use [\u00FC\u00DC] for the ü, but I need to be a bit more general (building the regex from other matcher groups). So according to javadocs:

By default, case-insensitive matching assumes that only characters in the US-ASCII charset are being matched. Unicode-aware case-insensitive matching can be enabled by specifying the UNICODE_CASE flag in conjunction with this flag.

Can anybody tell me how to specify the two flags in conjunction?


回答1:


Try

Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE

it should solve the issue. Or-ing the bitmask you will get compound features.




回答2:


Though more pure using parameters, same as "(?iu)gibt es ..." without parameters. i = case-insensitive, u = unicode.




回答3:


Use bitwise OR, like Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE.




回答4:


It's a bitmask, so you use the bitwise OR operator |.



来源:https://stackoverflow.com/questions/18332117/set-two-flags-in-java-regex-pattern

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