summaryrefslogtreecommitdiff
path: root/src/regex/RegexTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/regex/RegexTest.java')
-rw-r--r--src/regex/RegexTest.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/regex/RegexTest.java b/src/regex/RegexTest.java
new file mode 100644
index 0000000..097e4f7
--- /dev/null
+++ b/src/regex/RegexTest.java
@@ -0,0 +1,47 @@
+/*
+ * provide names and student id numbers here
+ */
+
+package regex;
+
+import dk.brics.automaton.RegExp;
+import dk.brics.automaton.RunAutomaton;
+
+public class RegexTest {
+
+ private final RunAutomaton r;
+
+ public RegexTest(String regex) {
+ System.out.println("regular expression = " + regex);
+ r = new RunAutomaton(new RegExp(regex).toAutomaton());
+ }
+
+ public long dfaMatch(String input, int index) {
+ long start = System.nanoTime();
+ int length = r.run(input, index);
+ long end = System.nanoTime();
+
+ if (length == -1) {
+ System.out.println("No match found!");
+ } else {
+ String s = input.substring(index, index + length);
+ System.out.println("Found: " + s);
+ }
+
+ return end - start;
+ }
+
+ void runTest(String input, int index) {
+ System.out.println("input string = " + input);
+ System.out.println("index = " + index);
+
+ long dfaMatchTime = dfaMatch(input, index);
+ System.out.println("dfaMatchTime " + dfaMatchTime);
+ }
+
+ public static void main(String[] args) {
+ RegexTest exampleRegexTest = new RegexTest("aap");
+ exampleRegexTest.runTest("aap_df34_d asdf sdfd", 0);
+ exampleRegexTest.runTest("a_a_pasdf sdfd", 0);
+ }
+}