- 正则验证
package main
import "regexp"
func main(){
account:="dsddasda12"
match,_:=regexp.MatchString(`^[a-z\d+]{6,15}$`,account)
if match{
fmt.Println("ok")
}else{
fmt.Println("fail")
}
}
- 正则取值
package main
import "regexp"
func main(){
account:="dsddasda12aaasa"
reg:= regexp.MustCompile(`^([a-z]+).\d+.(\w+)`)
attr:=reg.FindStringSubmatch(account)
fmt.Println(attr)
}
有疑问加站长微信联系(非本文作者)