【发布时间】:2016-03-17 19:30:54
【问题描述】:
public class StringMatchesCaseInsensitive
{
public static void main(String[] args)
{
String stringToSearch = "Four score and seven years ago our fathers ...";
// this won't work because the pattern is in upper-case
System.out.println("Try 1: " + stringToSearch.matches(".*SEVEN.*"));
// the magic (?i:X) syntax makes this search case-insensitive, so it returns true
System.out.println("Try 2: " + stringToSearch.matches("(?i:.*SEVEN.*)"));
}
}
上面的代码块就是这样的;不区分大小写搜索的示例。但我最感兴趣的是这个:"?i:.*SEVEN.*";。
我知道?:. 是不区分大小写的语法。但是封装SEVEN 的.* 呢?它有什么作用?
我在哪里可以了解更多关于 .、* 和 .* 正则表达式修饰符的信息?
提前致谢
【问题讨论】:
标签: java regex string syntax case-insensitive