简体   繁体   中英

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. 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). 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?

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. i = case-insensitive, u = unicode.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM