forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPossessiveQuantifiersLesson.java
More file actions
34 lines (30 loc) · 1.02 KB
/
Copy pathPossessiveQuantifiersLesson.java
File metadata and controls
34 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package regexp;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PossessiveQuantifiersLesson {
public static void main(String[] args) {
//*+ ++ ?+
Pattern p = Pattern.compile("\"[^\"]*+\"");
Matcher m = p.matcher("\"abc\"");
while(m.find()) {
System.out.print(m.start() + " " + m.group() + " ");
}
System.out.println("");
Pattern p2 = Pattern.compile("\".*+\"");
Matcher m2 = p2.matcher("\"abc\"x");
while(m2.find()) {
System.out.print(m2.start() + " " + m2.group() + " ");
}
System.out.println("");
//atomic group
//X*+ - (>X*)
// Pattern p3 = Pattern.compile("(?:a|b)*+b");
// Pattern p3 = Pattern.compile("(?>(?:a|b)*)b");
Pattern p3 = Pattern.compile("(?>a|b)*b");//not
Matcher m3 = p3.matcher("b");
while(m3.find()) {
System.out.print(m3.start() + " " + m3.group() + " ");
}
System.out.println("");
}
}