[英]VBA regex to find special characters in reverse
我正在尝试使用以下代码在单元格中查找特殊字符。 然而,仍然没有得到想要的。
我反向创建了正则表达式,它允许很少的特殊字符和字母数字,因为我们不知道/没有特殊字符列表。
Function spltrack(cell As String) 'Use Regular Expressiosn for grabbing the input and automatically filter it Dim regEx As New RegExp With regEx .Global = True .MultiLine = True .IgnoreCase = True .Pattern = "[0-9][a-zA-Z]|(\\[\\]())|.+-/|'&%#_:,!–" End With If regEx.Test(cell) Then spltrack = "Not Found" Else spltrack = "Found" End If End Function
代码或其他更好的方法有什么问题吗?
假设您想在有字母、数字和空格以外的字符时返回true :
With regEx
.Pattern = "[^0-9a-zA-Z\s()[\]:'""/&%#!_+,.|-]"
End With
If regEx.Test(cell) Then
spltrack = "Found"
Else
spltrack = "Not Found"
End If
解释
EXPLANATION
--------------------------------------------------------------------------------
[^0-9a-zA- any character except: '0' to '9', 'a' to
Z\s()[\]:'"/&%#!_+,. 'z', 'A' to 'Z', whitespace (\n, \r, \t,
|-] \f, and " "), '(', ')', '[', '\]', ':',
''', '"', '/', '&', '%', '#', '!', '_',
'+', ',', '.', '|', '-'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.