2016-01-16 43 views
0

如何判斷字符串是否包含IPv4地址。 我想在此字符串中獲得所有IP地址檢查字符串是否包含VB.Net中的IPv4地址

例:

下面的字符串包含4個IPv4地址:

2016-01-16 00:00 - [99.245.14.88] downloaded ... 
2016-01-16 00:00 - [120.103.139.95] downloaded ... 
2016-01-15 23:59 - [166.118.4.233] downloaded ... 
2016-01-15 23:59 - [55.234.129.191] downloaded ... 
+0

可能的重複[你如何從文件中使用正則表達式在Linux外殼中提取IP地址?](http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from -files-using-a-regex-in-a-linux-shell) –

回答

0

下面是一些代碼,我只是做了讓你每個IP ..

Dim Regex As New System.Text.RegularExpressions.Regex("\[(([\d]{1,3}\.?){4})\]", System.Text.RegularExpressions.RegexOptions.Multiline) 
    Dim matches As System.Text.RegularExpressions.MatchCollection = Regex.Matches(TextBox1.Text) 'Replace textbox with your string source 

    Dim tmp As String = "" 
    For Each match As System.Text.RegularExpressions.Match In matches 
     'Do something with each IP : match.Groups(1).Value 
     tmp &= match.Groups(1).Value & vbNewLine 
    Next 

    MsgBox(tmp) 

它採用了常規的表達,如果你要處理文本很多,你應該閱讀他們的工作方式。如果這是你正在尋找的東西,不要忘記標記爲答案,並讚揚。

+0

謝謝,它的工作原理。 –

相關問題