forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaRegexEx.java
More file actions
34 lines (23 loc) · 855 Bytes
/
JavaRegexEx.java
File metadata and controls
34 lines (23 loc) · 855 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
29
30
31
32
33
34
package com.zetcode;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// Regular expression - defines a search pattern for strings
// Pattern - compiled representation of a regular expression
// Matcher - engine that interprets the pattern and performs
// match operations against an input string.
public class JavaRegexEx {
public static void main(String[] args) {
List<String> words = List.of("Seven", "even",
"Maven", "Amen", "eleven");
Pattern p = Pattern.compile(".even");
for (String word: words) {
Matcher m = p.matcher(word);
if (m.matches()) {
System.out.printf("%s matches%n", word);
} else {
System.out.printf("%s does not match%n", word);
}
}
}
}