繁体   English   中英

如何在 VB.net 中使用正则表达式进行捕获

[英]How To Capture Using Regex In VB.net

我想从给定的源中使用 vb.net 中的正则表达式捕获dal.socks.ipvanish.com

</td>
 <td class="StatTDLabel">Dallas</td>
 <td class="StatTDLabel">dal.socks.ipvanish.com</td>
</tr>

这是我的一段代码,但这不起作用我不知道为什么有人能帮我弄清楚。

Dim str1 As Match = Regex.Match(TextBox1.Text, "<td class=""StatTDLabel"">(.*?)<\/td>\n                    <\/tr>")

TextBox2.Text = str1.Groups(1).Value

请参阅此处的正则表达式说明: https : //regex101.com/r/pJAD31/1

基本上你必须匹配StatTDLabel">的第二次出现,因为你的输入字符串有两次相同的出现。

在此处查看工作代码https://dotnetfiddle.net/W9lbVH

Imports System
Imports System.Text.RegularExpressions
                
Public Module Module1
    Public Sub Main()
        
        Dim pattern As String = "StatTDLabel"">.*?(StatTDLabel"">)(.*)<\/td>"
        Dim input As String = "</td> <td class=""StatTDLabel"">Dallas</td> <td class=""StatTDLabel"">dal.socks.ipvanish.com</td> </tr>"
        Dim options As RegexOptions = RegexOptions.Multiline
        Dim Match = Regex.Matches(input, pattern, options)
    
        Console.WriteLine (Match(0).Groups(2))
        
    End Sub
End Module

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM