通过正则表达式过滤掉 Html 个数字
Filter out Html Number Via Regex
我正在尝试从 html 源中过滤掉具有特定编号的特定行
问题是它在 100
和 25000
inc of +50
之间
我怎样才能让它在 100
和 25000
之间检查而不用写 100 行代码? txtAmount.text contains the website html source
这是我目前得到的:
Const Amount = "(<td class=""text-right"">100</td>)|(<td class=""text-right"">150</td>)|(<td class=""text-right"">200</td>)|(<td class=""text-right"">etc</td>)"
Dim qty As New List(Of String)
qty = txtAmount.Lines.ToList
For i As Integer = qty.Count - 1 To 0 Step -1
If Not Regex.IsMatch(qty(i), Amount) Then
qty.RemoveAt(i)
End If
Next
txtAmount.Lines = qty.ToArray
HTML:
<td class="text-right">100</td> <=== I need to get this number
您可以使用 \d
元字符来仅捕获数字(从 3 数字到 5 数字的范围示例):
Dim html As String =
"<td class=""text-right"">Quantity</td> <td class=""text-right"">100</td>"
Dim rgx As New Regex(".+text-right.+>(?<value>\d{3,5})<.+", RegexOptions.Singleline)
If rgx.IsMatch(html) Then
Dim value As Integer = CInt(rgx.Match(html).Groups("value").Value)
Console.WriteLine(value) ' 100 (or whatever other digits exists in the html field.)
End If
我正在尝试从 html 源中过滤掉具有特定编号的特定行
问题是它在 100
和 25000
inc of +50
我怎样才能让它在 100
和 25000
之间检查而不用写 100 行代码? txtAmount.text contains the website html source
这是我目前得到的:
Const Amount = "(<td class=""text-right"">100</td>)|(<td class=""text-right"">150</td>)|(<td class=""text-right"">200</td>)|(<td class=""text-right"">etc</td>)"
Dim qty As New List(Of String)
qty = txtAmount.Lines.ToList
For i As Integer = qty.Count - 1 To 0 Step -1
If Not Regex.IsMatch(qty(i), Amount) Then
qty.RemoveAt(i)
End If
Next
txtAmount.Lines = qty.ToArray
HTML:
<td class="text-right">100</td> <=== I need to get this number
您可以使用 \d
元字符来仅捕获数字(从 3 数字到 5 数字的范围示例):
Dim html As String =
"<td class=""text-right"">Quantity</td> <td class=""text-right"">100</td>"
Dim rgx As New Regex(".+text-right.+>(?<value>\d{3,5})<.+", RegexOptions.Singleline)
If rgx.IsMatch(html) Then
Dim value As Integer = CInt(rgx.Match(html).Groups("value").Value)
Console.WriteLine(value) ' 100 (or whatever other digits exists in the html field.)
End If