例1:
package main import ( "fmt" "regexp" ) func main() { s1 := "Z22WhkC9K$N#wRIbBitpQYUFJqd%d*QVz5Ir7j&CLqz3@FOC2x5CD6ZzvhNdk@5Vv1QU^DHbSc&nBs%4!94ngFH0BJ6GxtXg2$T" reg := regexp.MustCompile(`[^a-zA-Z0-9]`) fmt.Println(reg.FindAllString(s1, -1)) reg = regexp.MustCompile(`[a-zA-Z0-9]`) fmt.Println(reg.FindAllString(s1, -1)) reg = regexp.MustCompile(`[a-z]`) fmt.Println(reg.FindAllString(s1, -1)) reg = regexp.MustCompile(`[A-Z]`) fmt.Println(reg.FindAllString(s1, -1)) reg = regexp.MustCompile(`[0-9]`) fmt.Println(reg.FindAllString(s1, -1)) s2 := "河北省河南省hbshns湖北省hbshns湖南省" reg = regexp.MustCompile("[\u4e00-\u9fa5]") fmt.Println(reg.FindAllString(s2, -1)) reg = regexp.MustCompile(`[\p{Han}]+`) fmt.Printf("%q\n", reg.FindAllString(s2, -1)) reg = regexp.MustCompile(`[\P{Han}]+`) fmt.Printf("%q\n", reg.FindAllString(s2, -1)) }d:\goprojects\src\day1\正则\exp2>go run main.go
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。