regex - 如何在 VB.net 中使用正则表达式进行捕获
问题描述
我想dal.socks.ipvanish.com
在 vb.net 中使用正则表达式从给定的源中捕获。
</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
推荐阅读
- oracle - Oracle FlexCube Universal Banking - FLEXCUBE UBS 数据模型 - DDL 脚本位置
- mysql - 使用组连接时限制表选择
- ios - Safari 14.1.2 - 找不到变量:MediaRecorder
- javascript - `如何在单个按钮上应用多个事件?`
- android - 如何反编译 aab(android 应用程序包)?
- fortran - 如何使用while循环在fortran中读取文件?
- machine-learning - 选择用于评估模型性能的 IoU 和置信度阈值
- bash - 如何使用计时器监控命令的标准输出?
- python - 监控 Ram 使用和触发器,python 烧瓶
- javascript - 尝试使用 ajax 上传(不工作)