Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does FindIndex call pcre_exec twice? #13

Open
govcert-ch opened this issue Aug 2, 2019 · 0 comments
Open

Does FindIndex call pcre_exec twice? #13

govcert-ch opened this issue Aug 2, 2019 · 0 comments

Comments

@govcert-ch
Copy link

I have a question about FindIndex()(though I'm not sure if this project is still supported)... am I wrong, or does it call pcre_exec twice, first time via Matcher() - Reset() - Match() and then again via Match? I tried using the following replacement (Matchesinstead of Match), which seems to work, but I'm not sure if I miss something:

func (re *Regexp) FindIndex2(bytes []byte, flags int) []int {
	m := re.Matcher(bytes, flags)
	if m.Matches() {
		return []int{int(m.ovector[0]), int(m.ovector[1])}
	}
	return nil
}

However, I need the offset of all groups, not only the first one, plus additional information. Plus, I don't like changing other code, so I also tried this in my own code, which seems to work as well (but again, do I miss something?):

m := patt.Matcher(payload, 0)
if m.Matches() {
	grp := m.Group(0)
	off := len(payload) - cap(grp)

of curse this relies on the returned slice being part of the full subject array, which again is not perfect - but there is no official access to the offsets from outside the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant