From 9b7a78be8b811fb2fd7c7c54961a2a9f09530fe4 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 25 Apr 2016 16:39:02 +0200 Subject: Initial commit Unzipped from OASE (2IMP20), excluding the bin/ folder. size: 158596 bytes sha256: 179253d2bfec243bc5294372ce0ad1c5d82a30ef32ad108f6c9fd0aee73fe4df assignment1.zip --- src/regex/RegexTest.java | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/regex/RegexTest.java (limited to 'src') 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); + } +} -- cgit v1.2.1