• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

RegEx

How can I use Reg Expression to check a line if contain an IP address?
0
VBdotnet2005
Asked:
VBdotnet2005
2 Solutions
 
DarkHillCommented:
Got this off the xenocafe.com site, let me know if it works for you:

Private Function isIP(ByVal ip As String) As Boolean
    Dim regex As New RegularExpressions.Regex("^(?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(\.?\d)\.)){4}$")
    Return regex.IsMatch(ip)
End Function
0
 
planoczCommented:
darkhill  has it.
but this looks better.
Imports System.Text.RegularExpressions

 Private Function isIP(ByVal ip As String) As Boolean
        ' Return true if ip is in valid ip address format.
        Return Regex.IsMatch(ip, ("^(?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(\.?\d)\.)){4}$"))
    End Function
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now