|
@@ -1,6 +1,8 @@
|
1
|
1
|
import java.io.File;
|
2
|
2
|
import java.io.IOException;
|
3
|
3
|
import java.util.Scanner;
|
|
4
|
+import java.util.regex.Matcher;
|
|
5
|
+import java.util.regex.Pattern;
|
4
|
6
|
|
5
|
7
|
/**
|
6
|
8
|
* Created by thook on 10/7/15.
|
|
@@ -36,4 +38,41 @@ public class HamletParser {
|
36
|
38
|
return hamletData;
|
37
|
39
|
}
|
38
|
40
|
|
|
41
|
+ public String changeHamletToLeon(){
|
|
42
|
+
|
|
43
|
+ Pattern pattern = Pattern.compile(".*Hamlet.*");
|
|
44
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
45
|
+ return matcher.replaceAll("Leon");
|
|
46
|
+
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+ public String changeHoratioToTariq(){
|
|
51
|
+
|
|
52
|
+ Pattern pattern = Pattern.compile("Horatio");
|
|
53
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
54
|
+ return matcher.replaceAll("Tariq");
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ public boolean findHoratio(){
|
|
58
|
+// String ham= hamletData;
|
|
59
|
+// String regex = ".*Horatio.*";
|
|
60
|
+// boolean matcher= Pattern.matches(regex,ham);
|
|
61
|
+// System.out.println(matcher);
|
|
62
|
+// return matcher;
|
|
63
|
+// cannot use this method because matches expects char sequence but the given input is a text file.
|
|
64
|
+
|
|
65
|
+ Pattern pattern = Pattern.compile(".*Horatio.*");
|
|
66
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
67
|
+ return matcher.find();
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+ public boolean findHamlet(){
|
|
72
|
+
|
|
73
|
+ Pattern pattern = Pattern.compile("Hamlet");
|
|
74
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
75
|
+ return matcher.find();
|
|
76
|
+ }
|
|
77
|
+
|
39
|
78
|
}
|