如何在InSTR中使用RegEx表达式

时间:2011-01-13 21:23:08

标签: regex vb.net

所以我们要做的就是擦除一个类似于IP地址或任何数字集的任何内容的html文件。通常我要做的就是使用像string.split这样的东西来分割出我想搜索的区域周围的html。我想要做的是能够基本上搜索大量的字符以寻找与此注册模式匹配的任何内容。有关如何做到这一点的任何想法?

Dim pattern As String = "^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]):(\d{1,4}|[0-5]\d\d\d\d|[0-5]\d\d\d\d|6[0-4]\d\d\d|65[0-4]\d\d|655[0-2]\d|6553[0-5])$"

1 个答案:

答案 0 :(得分:1)

您可以执行以下操作,然后迭代匹配..

Dim pattern As String = "^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]):(\d{1,4}|[0-5]\d\d\d\d|[0-5]\d\d\d\d|6[0-4]\d\d\d|65[0-4]\d\d|655[0-2]\d|6553[0-5])$"

Dim matches As MatchCollection = Regex.Matches(someHTML, pattern)

For Each ipMatch As Match In matches
    Console.WriteLine(ipMatch.Value)
Next