(一)
import java.util.regex.*;
class RegexExamp {
public static void main(String[] args){
String content = "I am a nice man" + "runoob aa ni hao";
String temp = ".*runoob.*";
boolean isMatch = Pattern.matches(temp, content);
System.out.println("字符串中是否包含了'runoob'子字符串?"+isMatch);
}
}
字符串中是否包含了'runoob'子字符串?true
进程已结束,退出代码 0
(二)
import java.util.regex.*;
class RegexExamp {
public static void main(String[] args){
String content = "I am a nice man" + "runoob aa ni hao";
String temp = ".*save.*";
boolean isMatch = Pattern.matches(temp, content);
System.out.println("字符串中是否包含了'runoob'子字符串?"+isMatch);
}
}
字符串中是否包含了'runoob'子字符串?false
进程已结束,退出代码 0