1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

regex: fix find() when using anchors (start / end) (#18259)

This commit is contained in:
Felipe Pena
2023-05-25 04:51:41 -03:00
committed by GitHub
parent fc6a34355d
commit dc16e50d55
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,22 @@
import regex
fn test_anchor_start() {
mut re := regex.regex_opt(r'^\w+') or { panic(err) }
start, end := re.find('id.')
assert start == 0
assert end == 2
}
fn test_anchor_end() {
mut re := regex.regex_opt(r'\w+$') or { panic(err) }
start, end := re.find('(id')
assert start == 1
assert end == 3
}
fn test_anchor_both() {
mut re := regex.regex_opt(r'^\w+$') or { panic(err) }
start, end := re.find('(id)')
assert start == -1
assert end == -1
}