Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么regex.Match返回空字符串?_Regex_Vb.net - Fatal编程技术网

为什么regex.Match返回空字符串?

为什么regex.Match返回空字符串?,regex,vb.net,Regex,Vb.net,我只想获取字符串中与正则表达式匹配的部分,但尝试使用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 =

我只想获取字符串中与正则表达式匹配的部分,但尝试使用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

如果您的正则表达式以^开头,以$结尾,那么您正在尝试匹配整个字符串,而不是问题中所述的部分。
因此,您需要删除它们或重新表述您的问题。

如果您的正则表达式以“^”开头,以“$”结尾,则您试图匹配整个字符串,而不是问题中所述的部分。
因此,您需要删除它们或重新表述您的问题。

如果您的正则表达式以“^”开头,以“$”结尾,则您试图匹配整个字符串,而不是问题中所述的部分。
因此,您需要删除它们或重新表述您的问题。

如果您的正则表达式以“^”开头,以“$”结尾,则您试图匹配整个字符串,而不是问题中所述的部分。
因此,你要么删除它们,要么重新表述你的问题。

代码截图=不酷;粘贴为文本并使用代码格式化程序。代码截图=不酷;粘贴为文本并使用代码格式化程序。代码截图=不酷;粘贴为文本并使用代码格式化程序。代码截图=不酷;粘贴为文本并使用代码格式化程序。