forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDotLesson.java
More file actions
29 lines (25 loc) · 1 KB
/
Copy pathDotLesson.java
File metadata and controls
29 lines (25 loc) · 1 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
package regexp;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DotLesson {
public static void main(String[] args) {
//. - [^\n] unix - [^\r\n] windows
//mm/dd/yy
Pattern p = Pattern.compile("\\d\\d.\\d\\d.\\d\\d");
//Pattern p = Pattern.compile("\\d\\d[- /.]\\d\\d[- /.]\\d\\d");
Matcher m = p.matcher("02/12/03");
//Matcher m = p.matcher("02512703");
//Matcher m = p.matcher("grey");
while(m.find()) {
System.out.print(m.start() + " " + m.group() + " ");
}
System.out.println("");
Pattern p2 = Pattern.compile("\".*\"");
//Pattern p2 = Pattern.compile("\"[^\"\r\n]*\"");
Matcher m2 = p2.matcher("Put a \"string\" between double quotes");
// Matcher m2 = p2.matcher("Houston, we have a problem with \"string one\" and \"string two\". Please respond.");
while(m2.find()) {
System.out.print(m2.start() + " " + m2.group() + " ");
}
}
}