Java 中的matches()方法
目录
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.mybj123.com"); System.out.print("返回值 :" ); System.out.println(Str.matches("(.*)mybj123(.*)")); System.out.print("返回值 :" ); System.out.println(Str.matches("(.*)google(.*)")); System.out.print("返回值 :" ); System.out.println(Str.matches("www(.*)")); } }
以上程序执行结果为:
返回值 :true 返回值 :false 返回值 :true
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
码云笔记 » Java 中的matches()方法
码云笔记 » Java 中的matches()方法