#25 RegexHamletParser_JevitTith

Open
jtith wants to merge 1 commits from jtith/ZCW-Regex-Hamlet-Parser:master into master
1 changed files with 25 additions and 0 deletions
  1. 25
    0
      src/main/java/HamletReplacer.java

+ 25
- 0
src/main/java/HamletReplacer.java View File

@@ -0,0 +1,25 @@
1
+import java.util.regex.Matcher;
2
+import java.util.regex.Pattern;
3
+
4
+
5
+public class HamletReplacer {
6
+
7
+    private static Matcher matchPattern(String regex, String text){
8
+        Pattern pattern = Pattern.compile(regex);
9
+        return pattern.matcher(text);
10
+    }
11
+
12
+    private static String replaceMatch(Matcher m, String textToReplace){
13
+        return m.replaceAll(textToReplace);
14
+    }
15
+
16
+    public static void main(String[] args) {
17
+        HamletParser parser = new HamletParser();
18
+        String text = parser.getHamletData();
19
+
20
+        Matcher matcher = matchPattern("(Hamlet)+|(HAMLET)+", text);
21
+        String newText = replaceMatch(matcher,"LEON");
22
+        Matcher horatioMatcher = matchPattern("(Horatio)+|(HORATIO)+",newText);
23
+        String text2 = replaceMatch(horatioMatcher,"TARIQ");
24
+    }
25
+}