|
@@ -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
|
+}
|