This repository has been archived on 2025-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
chronozinc/parsing/extract.go
2016-12-05 16:35:06 +01:00

36 lines
601 B
Go

package parsing
import "regexp"
func Extract(file []byte, reg *regexp.Regexp) string {
submatches := reg.FindSubmatch(file)
if submatches == nil {
return ""
}
names := reg.SubexpNames()
for i, name := range names {
if name == "result" {
return string(submatches[i])
}
}
return ""
}
func ExtractLast(file []byte, reg *regexp.Regexp) string {
submatches := reg.FindAllSubmatch(file, -1)
if submatches == nil {
return ""
}
names := reg.SubexpNames()
for i, name := range names {
if name == "result" {
return string(submatches[len(submatches)-1][i])
}
}
return ""
}