package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^ # 匹配行首
(?=.*[A-Z]) # 向前环视,匹配到大写字母
(?=.*[a-z]) # 向前环视,匹配到小写字母
(?=.*\d) # 向前环视,匹配到数字
(?=.*[_\W]) # 向前环视,匹配到特殊字符
.{10,} # 若满足以上环视条件,且有10个以上字符,则进行匹配
$ # 匹配行尾`)
var str = `// Good Case
asdfsadfANVasdfasdfasdf..sadfs1
www.baidu.com.COM123
qwerTYUIOP1233333333333333
qwerTYUIOP1233333333333333-=+
asdfsafxxxSSS..123
abcABC123,./
// Bad Case
xxxyyyzzz
XYZxyz123
aaabbbccc
12342353125123asedf`
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/