Java matches() 方法
Java 教程
· 2019-02-08 23:12:26
matches() 方法用于检测字符串是否匹配给定的正则表达式。
调用此方法的 str.matches(regex) 形式与以下表达式产生的结果完全相同:
Pattern.matches(regex, str)
语法
public boolean matches(String regex)
参数
regex -- 匹配字符串的正则表达式。
返回值
在字符串匹配给定的正则表达式时,返回 true。
实例
public class Test {
public static void main(String args[]) {
String Str = new String("www.codercto.com");
System.out.print("返回值 :" );
System.out.println(Str.matches("(.*)codercto(.*)"));
System.out.print("返回值 :" );
System.out.println(Str.matches("(.*)google(.*)"));
System.out.print("返回值 :" );
System.out.println(Str.matches("www(.*)"));
}
}
以上程序执行结果为:
返回值 :true 返回值 :false 返回值 :true
点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html
TED Talks Storytelling: 23 Storytelling Techniques from the Best
Akash Karia / CreateSpace Independent Publishing Platform / 2015-1-11 / USD 6.99
"Every speaker can put these ideas into practice immediately -- and they should!" ~ Dr. Richard C. Harris, Certified World Class Speaking Coach "An insightful read" ~Dennis Waller, Top 500 Revie......一起来看看 《TED Talks Storytelling: 23 Storytelling Techniques from the Best》 这本书的介绍吧!