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-数据库约束
- 下一篇: 撸表情开发过程中使用腾讯云存储的接入实例