matches()方法
生活随笔
收集整理的這篇文章主要介紹了
matches()方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
java.lang包中的String類和java.util.regex包中的Pattern,Matcher類中都有matches()方法,都與正則表達式有關。
下面我分別舉例:(字符串:"abc",正則表達式: "[a-z]{3}"
)
String類的方法:
boolean b = "abc".matches("[a-z]{3}"
System.out.println(b);
Pattern類中的方法:
boolean b = Pattern.matches("[a-z]{3}","abc");
System.out.println(b);
Matcher類中的方法:
Pattern p = Pattern.compile("[a-z]{3}");
Matcher m = p.matcher("acc");
boolean b =m.matches()
System.out.println(b);
得到的結果都為true。
下面我分別舉例:(字符串:"abc",正則表達式: "[a-z]{3}"
)
String類的方法:
boolean b = "abc".matches("[a-z]{3}"
System.out.println(b);
Pattern類中的方法:
boolean b = Pattern.matches("[a-z]{3}","abc");
System.out.println(b);
Matcher類中的方法:
Pattern p = Pattern.compile("[a-z]{3}");
Matcher m = p.matcher("acc");
boolean b =m.matches()
System.out.println(b);
得到的結果都為true。
轉載于:https://www.cnblogs.com/liwendeboke/p/6054690.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的matches()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一、SQL语法——4-数据库约束
- 下一篇: 撸表情开发过程中使用腾讯云存储的接入实例