package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^https?:\/\/www\.example\.com(?:\/[a-zA-Z]+)*(?:\/\d+\.html)?$`)
var str = `https://www.example.com
https://www.example.com/demo
https://www.example.com/demo/abc
https://www.example.com/demo/abc/123.html
不匹配:
https://www.example.com/demo/abc/efg123.html
(可能含有数字)`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
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/