How To Use RegEx Expression with InSTR
So wha ti'm looking to do is scrub an html file for anything that resembles an IP address or any set of numbers for that matter. Normally what I would do is just using things like string.split to split out the h开发者_运维百科tml around areas that I want to search. What im looking to do is be able to essentially search a large amount of characters for anything that matches this reg ex pattern. Any ideas on how to do that?
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])$"
You could do something like below and then iterate over the matches..
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
精彩评论