一、限定符
1 ?(?前的单个字符可以出现1次或0次)
String[] s = {"a","ab","abb","abbbbb","ac"};//java代码
for (int i=0; i< s.length; i++) {
if (s[i].matches("ab?"))
System.out.println(s[i]);
}
输出结果: a , ab
2 * (*前边的单个字符出现0字或多次)
public static void main(String[] args) {//java代码
String[] s = {"a","ac","ab","adc","abbc","abbbbbc"};
for (int i=0; i< s.length; i++) {
if (s[i].matches("ab*c"))//正则表达式
System.out.println(s[i]);
}
}
输出结果:ac ,abbc , abbbbbc
3 + (+前边的单个字符出现1次以上的字符)
public static void main(String[] args