Golang 正则匹配 -- regexp

匹配特殊字符

//re :=regexp.MustCompile("[~!@#$%^&*(){}|<>\\\\/+\\-【】:\"?':;‘’“”,。、《》\\]\\[`]")
//re :=regexp.MustCompile("[!-/]|[:-@]|[\\[-`]")
re :=regexp.MustCompile("[\u0020-\u002F]|[\u003A-\u0040]|[\u005B-\u0060]|[\u00A0-\u00BF]")
return re.MatchString(str)

以上三种写法等效,须要注意的是若是在 [] 规则内包含 [] 符号,须要前面加\\.code

相关文章
相关标签/搜索