为什么regex.Match返回空字符串?
问题描述:
我只是想获得与正则表达式,但与match.Value或团体,它总是返回“”努力相匹配的字符串的一部分。这让我疯狂。 编辑:
这工作:
Private Function NormalizeValue(ByVal fieldValue As String) As String
Dim result As String = ""
Dim pattern As String = "[a-zA-Zñ'-]*"
Dim matches As Match
matches = Regex.Match(fieldValue, pattern)
While (matches.Success = True)
result = result & matches.Value
matches = matches.NextMatch()
End While
Return result
End Function
答
如果您正则表达式用^开始,以$结束,你想整个字符串匹配 - 为您在这个问题说明不是部分。 所以你要么删除它们,要么重新解释你的问题。
+0
谢谢!这解决了我的问题。 – user1824644 2015-01-21 03:00:46
你的代码截图= not cool;粘贴为文本并使用代码格式化程序。 – 2015-01-20 23:09:07