Golang 正则匹配 -- regexp

匹配特殊字符

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

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

posted @ 2019-05-28 20:07  王的博客  阅读(9135)  评论(0编辑  收藏  举报