Reputation: 23
I have:
getObj("TextPPPIPAddress0").value="31.205.102.255";
I want get IP with Regex, I'm new with regex and I have conflict on ". My code:
MatchCollection m1 = Regex.Matches(html, "getObj((\")TextPPPIPAddress0(\")).value=(\")(.+?)(\")", RegexOptions.Singleline);
I want result 31.205.102.255
Upvotes: 0
Views: 947
Reputation: 15445
I would use
var ip = IPAddress.Parse(ipString);
IPAddress
is in System.Net
and already does what you want to do for you. You can use TryParse()
if you want the boolean return value instead.
Upvotes: 5
Reputation: 3018
Try:
Regex ip = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b");
MatchCollection result = ip.Matches(getObj("TextPPPIPAddress0").value);
Console.WriteLine(result[0]);
Upvotes: 0