不包含特定字符串的Java正则表达式。

示例

import java.util.regex.*;
class PatternMatch{
   public static void main(String args[]) {
      String content = "I am a student";
      String string = ".*boy.*";
      boolean isMatch = Pattern.matches(string,content);
      System.out.println("The line contains 'boy'?"+ isMatch);
   }
}

输出结果

the line contains 'boy'?false

火柴()

用于检查整个文本是否与模式匹配。其输出为布尔值。如果找到匹配项则返回true,否则返回false。这是使用Regex搜索文本中字符串的最简单方法之一,还有另一种方法compile(),如果您要进行CASE INSENSITIVE搜索或要搜索多次出现可以使用。

对于上面的示例,它将是-

String content = "I am a student";
String string = ".*BoY.";
Pattern pattern = Pattern.compile(string, Pattern.CASE_INSENSITIVE);