正则表达式 - 如何单独挑选这些整数

时间:2016-12-21 13:27:36

标签: regex vb.net

我有以下HTML,我试图分开。出于某种原因,我无法弄清楚正则表达式(诚然,我很擅长):

<td class="score">
    286

        <span class="pos">(2455 of 3921)</span>

</td>

我希望单独取出3个整数。所以,基本上:

  • 得分= 286
  • 地方= 2455
  • 参赛作品= 3921

我浏览了数字范围&#39; regular-expressions.info上的页面,但仍然无法弄明白!是的,我知道这很容易......显然我的大脑无法理解这种逻辑。

我将在vb.net,BTW中使用它。如果重要。

2 个答案:

答案 0 :(得分:0)

此正则表达式获取字符串中的所有数字。

/\d+/g;

答案 1 :(得分:0)

Here's a simple example of code that does it for you at ideone.com

肠道看起来像:

Dim regex As Regex = New Regex("(\d+)[^\d]*(\d+)[^\d]*(\d+)")
Dim match As Match = regex.Match("<td class='score'>    286          <span class='pos'>(2455 of 3921)</span> </td>")
If match.Success Then
    Console.WriteLine(match.Groups(1).Value)
    Console.WriteLine(match.Groups(2).Value)
    Console.WriteLine(match.Groups(3).Value)
End If
相关问题