简体   繁体   中英

Java case insensitive regular expression

I just got this:

System.out.println("КОНТАКТЫ".matches("(?i).*контакт.*"));

and it always says "false".

I tried:

System.out.println("КОНТАКТЫ".matches("(?i:.*контакт.*)"));

and:

System.out.println("КОНТАКТЫ".matches("(?i:).*контакт.*"));

and:

System.out.println("КОНТАКТЫ".matches("(?i)^.*контакт.*$"));

and many others variations but I always have "false".

How to perform case insensitive search in java correctly so I have "true" in this regexp search?

What do I do wrong?

What you need is to turn unicode case flag on:

System.out.println("КОНТАКТЫ".matches("(?iu).*контакт.*"));

More here

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