Golang 正则匹配 -- regexp

匹配特殊字符

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

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

原文地址:https://www.cnblogs.com/cnblogs-wangzhipeng/p/10939899.html