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