数量词
Greedy 数量词
X?的含义:
X,一次或一次也没有
X*的含义:
X,零次或多次
X+的含义:
X,一次或多次
X{n}的含义:
X,恰好 n 次
X{n,}的含义:
X,至少 n 次
X{n,m}的含义:
X,至少 n 次,但是不超过 m 次
package com.heima.regex;
public class Demo04_Regex {
public static void main(String[] args) {
//demo1();
//demo2();
//demo3();
//demo4();
//demo5();
String regex = "[abc]{5,15}";
System.out.println("abcba".matches(regex));
System.out.println("abcbaabcabbabab".matches(regex));
System.out.println("abcb".matches(regex));
System.out.println("abcbaabaabcbaaba".matches(regex));
}
public static void demo5() {
String regex = "[abc]{5,}";
System.out.println("abcba".matches(regex));
System.out.println("abcbaabcabbabab".matches(regex));
System.out.println("abcb".matches(regex));
System.out.println("abcbaaba".matches(regex));
}
public static void demo4() {
String regex = "[abc]{5}";
System.out.println("abcba".matches(regex));
System.out.println("abcbaabcabbabab".matches(regex));
System.out.println("abcb".matches(regex));
System.out.println("abcbaaba".matches(regex));
}
public static void demo3() {
String regex = "[abc]+";
System.out.println("".matches(regex));
System.out.println("a".matches(regex));
System.out.println("aaaaabbbbccccc".matches(regex));
}
public static void demo2() {
String regex = "[abc]*";
System.out.println("".matches(regex));
System.out.println("abc".matches(regex));
System.out.println("a".matches(regex));
}
public static void demo1() {
String regex = "[abc]?";
System.out.println("a".matches(regex));
System.out.println("b".matches(regex));
System.out.println("c".matches(regex));
System.out.println("d".matches(regex));
System.out.println("".matches(regex));
}
}
博客主要介绍了Greedy数量词相关内容,详细阐述了X?、X*、X+、X{n}、X{n,}、X{n,m}等不同形式的含义,如X?表示X一次或一次也没有,X*表示X零次或多次等。
2535

被折叠的 条评论
为什么被折叠?



