matches()方法
生活随笔
收集整理的這篇文章主要介紹了
matches()方法
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
java.lang包中的String類和java.util.regex包中的Pattern,Matcher類中都有matches()方法,都與正則表達(dá)式有關(guān)。
下面我分別舉例:(字符串:"abc",正則表達(dá)式: "[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);
得到的結(jié)果都為true。
下面我分別舉例:(字符串:"abc",正則表達(dá)式: "[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);
得到的結(jié)果都為true。
轉(zhuǎn)載于:https://www.cnblogs.com/liwendeboke/p/6054690.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的matches()方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一、SQL语法——4-数据库约束
- 下一篇: 撸表情开发过程中使用腾讯云存储的接入实例