要设置Java Matcher的匹配模式为不区分大小写,可以使用Pattern.CASE_INSENSITIVE标志。示例如下:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String text = "Hello, World!";
Pattern pattern = Pattern.compile("hello", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
System.out.println("Match found!");
} else {
System.out.println("Match not found!");
}
}
}
在上面的示例中,使用Pattern.compile方法并传递Pattern.CASE_INSENSITIVE标志来创建不区分大小写的匹配模式。然后使用Matcher对象来查找匹配项。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:Java中Pattern.compile函数的使用详解