@@ -5,49 +5,44 @@ use com.ibm.streamsx.regex.re2::*;
55/**
66* Run functional tests using native functions.
77*
8- * * Functional tests for simple, partial and full matches.
8+ * * Functional tests for interpreted and compiled partial/ full matches.
99*
1010* The output:
11- * * regexSimpleMatch: 'Hello world' matches '^Hello': true
12- * * regexSimpleMatch: 'Hello world' matches 'Hello$': false
1311* * regexPartialMatch: 'Hello world' matches '^Hello': true
12+ * * regexFullMatch: 'Hello world' matches '^Hello': true
1413* * regexPartialMatch: 'Hello world' matches '^Hello': true
15- * * regexPartialMatch: 'Hello world' matches 'Hello$': true
1614* * regexFullMatch: 'Hello world' matches '^Hello': false
17- * * regexFullMatch: 'Hello world' matches '^ Hello world': false
15+ * * regexFullMatch: 'Hello world' matches 'Hello world$ ': true
1816*/
1917composite RegexMatchNFSample {
2018 graph
2119 ()as Custom_1 = Custom(){
2220 logic
2321 onProcess : {
24- // Simple partial match - regex pattern is interpreted on each call
25- // The usage is similar to SPL regex functions
26- printString("regexSimpleMatch: 'Hello world' matches '^Hello': ");
27- println(regexSimpleMatch("Hello world", "^Hello"));
28-
29- printString("regexSimpleMatch: 'Hello world' matches 'Hello$': ");
30- println(regexSimpleMatch("Hello world", "Hello$"));
22+ // Compile and index regex pattern, additionally increase max memory allocated
23+ regexCompile("^Hello", RegexPattern._1);
24+ regexCompile("Hello world$", RegexPattern._2);
25+ regexCompile(".*VERY_BIG_PATTERN.*", RegexPattern._3, 10000000);
3126
32- // Fast partial match - regex pattern is compiled on the first call
33- // Each subsequent call will use the compiled version even if the new pattern given
27+ // Simple partial match (similar to SPL regex functions) - regex pattern is interpreted on each call
3428 printString("regexPartialMatch: 'Hello world' matches '^Hello': ");
3529 println(regexPartialMatch("Hello world", "^Hello"));
3630
31+ // Simple full match (the whole string is matched) - regex pattern is interpreted on each call
32+ printString("regexFullMatch: 'Hello world' matches '^Hello world': ");
33+ println(regexFullMatch("Hello world", "^Hello world"));
34+
35+ // Fast partial match - compiled regex pattern 1 is used
3736 printString("regexPartialMatch: 'Hello world' matches '^Hello': ");
38- println(regexPartialMatch("Hello world"));
37+ println(regexPartialMatch("Hello world", RegexPattern._1 ));
3938
40- printString("regexPartialMatch: 'Hello world' matches 'Hello$': ");
41- println(regexPartialMatch("Hello world", "Hello$")); // Still using compiled '^Hello' pattern
42-
43- // Fast full match is similar to the partial match, but requires to match the whole string
44- // Existing regex pattern still applies as it was compiled on previous call
39+ // Fast full match - compiled regex pattern 1 is used
4540 printString("regexFullMatch: 'Hello world' matches '^Hello': ");
46- println(regexFullMatch("Hello world"));
41+ println(regexFullMatch("Hello world", RegexPattern._1 ));
4742
48- printString("regexFullMatch: 'Hello world' matches '^Hello world': ");
49- println(regexFullMatch(" Hello world", "^ Hello world")); // new pattern is not used
50-
43+ // Fast full match - compiled regex pattern 2 is used
44+ printString("regexFullMatch: ' Hello world' matches ' Hello world$': ");
45+ println(regexFullMatch("Hello world", RegexPattern._2));
5146 }
5247
5348 }
0 commit comments