【问题标题】:Java Case Insensitive Method Breakdown and Explanation [closed]Java 不区分大小写的方法分解和解释 [关闭]
【发布时间】: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


    【解决方案1】:

    以下是这些符号所代表的含义。

    • . 代表除换行符以外的任何字符。如果与s 标志一起使用,那么它也匹配换行符。

    • * 是量词,表示zero or many

    • .* 会说zero or many characters

    您可以在

    上阅读有关它们的更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      • 2013-03-06
      相关资源
      最近更新 更多