mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
regex: fix issue with multiple repetitions out of the groups (#17774)
This commit is contained in:
parent
24cc5920e6
commit
3d2d330478
|
@ -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
|
// stop already started matching outside a capturing group
|
||||||
if re.state_list.len > 0 && re.state_list.last().group_index == -1
|
if re.state_list.len > 0 && re.state_list.last().group_index == -1
|
||||||
&& re.state_list.last().last_dot_pc > 0 {
|
&& 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
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import regex
|
import regex
|
||||||
|
|
||||||
fn test_complex_matching() {
|
fn test_complex_matching001() {
|
||||||
tmp_text := r"[export:'something']
|
tmp_text := r"[export:'something']
|
||||||
const (
|
const (
|
||||||
some_const = [1114111, 127, 2047, 65535, 1114111]!
|
some_const = [1114111, 127, 2047, 65535, 1114111]!
|
||||||
|
@ -17,3 +17,38 @@ empty_const = ()
|
||||||
mut a := re.find_all(tmp_text)
|
mut a := re.find_all(tmp_text)
|
||||||
assert a == [86, 138]
|
assert a == [86, 138]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_complex_matching002() {
|
||||||
|
text := '<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="v_app_name">V0</string>
|
||||||
|
<!-- comment -->
|
||||||
|
<string name="v_lib_name">v1</string>
|
||||||
|
<string name="v_lib_name2">v2</string>
|
||||||
|
</resources>
|
||||||
|
'
|
||||||
|
|
||||||
|
mut re := regex.regex_opt(r'.*<resources>.+<string name="v_lib_name">([^<]+)') 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 := 'abcdefgt1234abcd<tag name="mio_tag">value</tag>'
|
||||||
|
|
||||||
|
mut re := regex.regex_opt(r'\w*<tag\s*name\s*="mio_tag">([^<]+)') 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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user