package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^\/foo\/([^\/]+)$`)
var str = `// Take this string: /foo/bar
// which should be applied to: /foo/?
// where the question mark means required parameter.
So the following should be correct:
/foo/bar
and the following should be wrong:
/foo
/foo/
/foo/bar/abc`
if len(re.FindStringIndex(str)) > 0 {
fmt.Println(re.FindString(str),"found at index",re.FindStringIndex(str)[0])
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/