-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegex.java
More file actions
28 lines (24 loc) · 731 Bytes
/
Regex.java
File metadata and controls
28 lines (24 loc) · 731 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
28
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Regex {
public static void main(final String[] args) {
Regex r = new Regex();
r.matchAnything();
r.beginingAndEnding();
}
void matchAnything() {
Pattern r = Pattern.compile(".");
String anything = "hello world";
Matcher m = r.matcher(anything);
System.out.println(m.find());
}
void beginingAndEnding() {
Pattern r = Pattern.compile("^hel");
String word = "hello world";
Matcher m = r.matcher(word);
System.out.println(m.find());
r = Pattern.compile("orld$");
m = r.matcher(word);
System.out.println(m.find());
}
}