diff --git a/vlib/regex/regex.v b/vlib/regex/regex.v index 2d0d2d7400..65f5875a95 100644 --- a/vlib/regex/regex.v +++ b/vlib/regex/regex.v @@ -2520,7 +2520,9 @@ pub fn (mut re RE) match_base(in_txt &u8, in_txt_len int) (int, int) { // stop already started matching outside a capturing group if re.state_list.len > 0 && re.state_list.last().group_index == -1 && re.state_list.last().last_dot_pc > 0 { - return regex.no_match_found, 0 + if ist == regex.ist_dot_char || ist == regex.ist_bsls_char { + return regex.no_match_found, 0 + } } continue } diff --git a/vlib/regex/regex_complex_test.v b/vlib/regex/regex_complex_test.v index 22edd0cf9c..12861935eb 100644 --- a/vlib/regex/regex_complex_test.v +++ b/vlib/regex/regex_complex_test.v @@ -1,6 +1,6 @@ import regex -fn test_complex_matching() { +fn test_complex_matching001() { tmp_text := r"[export:'something'] const ( some_const = [1114111, 127, 2047, 65535, 1114111]! @@ -17,3 +17,38 @@ empty_const = () mut a := re.find_all(tmp_text) assert a == [86, 138] } + +fn test_complex_matching002() { + text := ' + + V0 + + v1 + v2 + +' + + mut re := regex.regex_opt(r'.*.+([^<]+)') or { panic(err) } + + start, end := re.match_string(text) + if start >= 0 && re.groups.len > 0 { + // check that we have obtained our 'v1' value + assert text#[re.groups[0]..re.groups[1]] == 'v1' + return + } + assert false +} + +fn test_complex_matching003() { + text := 'abcdefgt1234abcdvalue' + + mut re := regex.regex_opt(r'\w*([^<]+)') or { panic(err) } + + start, end := re.match_string(text) + if start >= 0 && re.groups.len > 0 { + println('found ${text#[start..end]}') + println('group: ${text#[re.groups[0]..re.groups[1]]}') + return + } + assert false +}