diff --git a/vlib/regex/regex_test.v b/vlib/regex/regex_test.v index 8fc9fa7096..e9a3baf1ce 100644 --- a/vlib/regex/regex_test.v +++ b/vlib/regex/regex_test.v @@ -556,6 +556,13 @@ fn test_regex(){ continue } + // test the match predicate + if to.s >= 0 { + assert re.matches_string(to.src) + } else { + assert !re.matches_string(to.src) + } + // rerun to test consistency tmp_str1 := to.src.clone() start1, end1 := re.match_string(tmp_str1) @@ -637,4 +644,4 @@ fn test_quantifier_sequences(){ } assert re_err == regex.err_syntax_error } -} \ No newline at end of file +} diff --git a/vlib/regex/regex_util.v b/vlib/regex/regex_util.v index bad5d727fc..060d01dabb 100644 --- a/vlib/regex/regex_util.v +++ b/vlib/regex/regex_util.v @@ -144,6 +144,12 @@ pub fn (mut re RE) match_string(in_txt string) (int, int) { return start, end } +// matches_string Checks if the pattern matches the in_txt string +pub fn (mut re RE) matches_string(in_txt string) bool { + start, _ := re.match_string(in_txt) + return start != no_match_found +} + /****************************************************************************** * * Finders