Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go regexp #291

Open
itcuihao opened this issue Jun 14, 2019 · 0 comments
Open

Go regexp #291

itcuihao opened this issue Jun 14, 2019 · 0 comments
Labels

Comments

@itcuihao
Copy link
Owner

func reg() {
	// 判断汉字字母数字
	s := "nihao你好243"
	// str := `^[\u4e00-\u9fa5]+$`
	//     d:\mygo\src\ch\t>go test -v -run TestReg
	// === RUN   TestReg
	// --- FAIL: TestReg (0.00s)
	// panic: regexp: Compile(`^[\u4e00-\u9fa5]+$`): error parsing regexp: invalid escape sequence: `\u` [recovered]
	//         panic: regexp: Compile(`^[\u4e00-\u9fa5]+$`): error parsing regexp: invalid escape sequence: `\u`
	// str := "^[a-zA-Z0-9\u4e00-\u9fa5]+$"  // ok
	// str := `^[a-z0-9A-Z\p{Han}]+(_[a-z0-9A-Z\p{Han}]+)*?$`
	str := `^[a-z0-9A-Z\p{Han}]+$` // ok
	r := regexp.MustCompile(str)
	b := r.MatchString(s)
	fmt.Println(b)
}
@itcuihao itcuihao added the Go label Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant