模式对象和匹配器对象的基本使用
把规则转换为模式对象
Pattern p = Pattern.compile("a*b");
通过模式对象得到匹配器对象
Matcher m = p.matcher("aaaaab");通过匹配器对象调用功能
boolean b = m.matches();
System.out.println(b);
作为判断来说
String s = "aaaaab";
String regex = "a*b";
boolean flag = s.matches(regex);
System.out.println(flag);
使用例子:
Pattern p = Pattern.compile(regex); Matcher m = p.matcher(s);
具体可以参考如下博客,讲的很详细:
http://blog.csdn.net/yin380697242/article/details/52049999
http://blog.csdn.net/woniu317/article/details/52186694