forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipeLesson.java
More file actions
27 lines (24 loc) · 991 Bytes
/
Copy pathPipeLesson.java
File metadata and controls
27 lines (24 loc) · 991 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
26
27
package regexp;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PipeLesson {
public static void main(String[] args) {
Pattern p = Pattern.compile("cat|dog");
Matcher m = p.matcher("I like my dog!");
while(m.find()) {
System.out.print(m.start() + " " + m.group() + " ");
}
System.out.println("");
Pattern p2 = Pattern.compile("Get|GetValue|Set|SetValue");
// Pattern p2 = Pattern.compile("Get|GetValue|SetValue|Set");
// Pattern p2 = Pattern.compile("Get(Value)|Set(Value)");
// Pattern p2 = Pattern.compile("\\b(Get|GetValue|Set|SetValue)\\b");
// Pattern p2 = Pattern.compile("\\b(Get(Value)?|Set(Value)?)\\b");
// Pattern p2 = Pattern.compile("\b(Get|Set)(Value)?\b");
Matcher m2 = p2.matcher("SetValue");
while(m2.find()) {
System.out.print(m2.start() + " " + m2.group() + " ");
}
System.out.println("");
}
}