Skip to content
Advertisement

Set two flags in Java regex.Pattern

I need a matcher like this:

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

and the problem is that it is not simple ASCII. I know that in this particular case I could use [u00FCu00DC] 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?

Advertisement

Answer

Try

Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE

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

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement