forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchingModeLesson.java
More file actions
25 lines (22 loc) · 942 Bytes
/
Copy pathMatchingModeLesson.java
File metadata and controls
25 lines (22 loc) · 942 Bytes
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
package regexp;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MatchingModeLesson {
public static void main(String[] args) {
// Pattern p = Pattern.compile("a", Pattern.CASE_INSENSITIVE);
Pattern p = Pattern.compile("A#this is commet", Pattern.COMMENTS);
// Pattern p = Pattern.compile("a", Pattern.MULTILINE);
Matcher m = p.matcher("A");
while(m.find()) {
System.out.print(m.start() + " " + m.group() + " ");
}
System.out.println("");
System.out.println("A".matches("(?i)a"));
"A".matches("(?s)a");//single line
"A".matches("(?m)a");//multiline
System.out.println("A".matches("(?x)A#this is comment"));//commetnts
System.out.println("A".matches("(?ix)a#this is comment"));
System.out.println("AA".matches("(?i)a(?-i)a"));
System.out.println("AAA".matches("(?i)a(?-i:A)a"));
}
}