不包含特定字符串的 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
matches()
它用于检查整个文本是否与模式匹配。它的输出是布尔值。如果找到匹配项,则返回 true,否则返回 false。这是使用正则表达式在文本中搜索字符串的最简单、最容易的方法之一。还有另一个方法 compile(),如果你想要进行不区分大小写的搜索或想要进行多次出现搜索,可以使用这个方法。
对于上面的示例,它将是:
String content = "I am a student"; String string = ".*BoY."; Pattern pattern = Pattern.compile(string, Pattern.CASE_INSENSITIVE);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP