正则表达式匹配行和特殊结束的开头

时间:2021-12-21 15:24:32

how can I match the beginning of a line with keyword "dog" that the end is a equal sign what I have is not working

我如何匹配一行的开头与关键字“狗”,结果是一个等号,我有什么不工作

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim iString As String = "cats=123" & vbCrLf & "dog=456"
    Dim q1 = System.Text.RegularExpressions.Regex.Match(iString, "^dog=")
    If q1.Success Then
        Debug.Print("found")
    Else
        Debug.Print("not found")
    End If
End Sub

1 个解决方案

#1


1  

You had it almost ok, you just need an option to treat the input as multi line:

你几乎可以,你只需要一个选项来将输入视为多行:

Dim q1 = System.Text.RegularExpressions.Regex.Match(iString, "^dog=", RegexOptions.Multiline)

#1


1  

You had it almost ok, you just need an option to treat the input as multi line:

你几乎可以,你只需要一个选项来将输入视为多行:

Dim q1 = System.Text.RegularExpressions.Regex.Match(iString, "^dog=", RegexOptions.Multiline)