[英]Set two flags in Java regex.Pattern
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. 问题是它不是简单的ASCII。 I know that in this particular case I could use [\ü\Ü] for the ü, but I need to be a bit more general (building the regex from other matcher groups). 我知道在这种特殊情况下我可以使用[\\ u00FC \\ u00DC]作为ü,但我需要更一般(从其他匹配器组构建正则表达式)。 So according to javadocs : 所以根据javadocs :
By default, case-insensitive matching assumes that only characters in the US-ASCII charset are being matched. 默认情况下,不区分大小写的匹配假定只匹配US-ASCII字符集中的字符。 Unicode-aware case-insensitive matching can be enabled by specifying the UNICODE_CASE flag in conjunction with this flag. 通过将UNICODE_CASE标志与此标志一起指定,可以启用Unicode感知的不区分大小写的匹配。
Can anybody tell me how to specify the two flags in conjunction? 任何人都可以告诉我如何同时指定两个标志?
Try 尝试
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE
it should solve the issue. 它应该解决这个问题。 Or-ing the bitmask you will get compound features. 或者使用位掩码,您将获得复合功能。
Though more pure using parameters, same as "(?iu)gibt es ..."
without parameters. 虽然使用参数更纯,但与没有参数的"(?iu)gibt es ..."
。 i
= case-insensitive, u
= unicode. i
=不区分大小写, u
= unicode。
Use bitwise OR, like Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE
使用按位OR,如Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE
. Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE
。
It's a bitmask, so you use the bitwise OR operator |
它是一个位掩码,因此您使用按位OR运算符|
. 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.