此字符串是否与给定的正则表达式匹配,以str.matches(regex)形式调用此方法所产生的输出与表达式Pattern.matches(regex,str)完全相同。
这是此方法的语法-
public boolean matches(String regex)
这是参数的详细信息-
regex - 此字符串要匹配的正则表达式。
仅当此字符串与给定的正则表达式匹配时,此方法返回true。
import java.io.*; public class Test { public static void main(String args[]) { String Str=new String("Welcome to Learnfk.com"); System.out.print("返回值 :" ); System.out.println(Str.matches("(.*)Learnfk(.*)")); System.out.print("返回值 :" ); System.out.println(Str.matches("LearnFk")); System.out.print("返回值 :" ); System.out.println(Str.matches("Welcome(.*)")); } }
这将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/java/java-string-matches.html
来源:LearnFk无涯教程网
返回值 :true 返回值 :false 返回值 :true
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)