We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b5671f5 commit 095a923Copy full SHA for 095a923
1 file changed
regex/JavaRegexAnchor.java
@@ -0,0 +1,31 @@
1
+package com.zetcode;
2
+
3
+import java.util.Arrays;
4
+import java.util.List;
5
+import java.util.regex.Matcher;
6
+import java.util.regex.Pattern;
7
8
+// Anchors match positions of characters inside a given text.
9
10
+public class JavaRegexAnchor {
11
12
+ public static void main(String[] args) {
13
14
+ List<String> sentences = Arrays.asList("I am looking for Jane.",
15
+ "Jane was walking along the rive.",
16
+ "Kate and Jane are close friends.");
17
18
+ Pattern p = Pattern.compile("^Jane");
19
20
+ for (String word : sentences) {
21
22
+ Matcher m = p.matcher(word);
23
24
+ if (m.find()) {
25
+ System.out.printf("%s matches%n", word);
26
+ } else {
27
+ System.out.printf("%s does not match%n", word);
28
+ }
29
30
31
+}
0 commit comments