我有:
getObj("TextPPPIPAddress0").value="31.205.102.255";
我想用Regex获得IP,我是Regex的新手,我有冲突。我的代码:
MatchCollection m1 = Regex.Matches(html, "getObj((")TextPPPIPAddress0(")).value=(")(.+?)(")", RegexOptions.Singleline);
I want result 31.205.102.255
我会用
var ip = IPAddress.Parse(ipString);
IPAddress
在System.Net
中,并且已经为您做了您想做的事情。如果您想要布尔返回值,则可以使用TryParse()
。
尝试:
Regex ip = new Regex(@"bd{1,3}.d{1,3}.d{1,3}.d{1,3}b");
MatchCollection result = ip.Matches(getObj("TextPPPIPAddress0").value);
Console.WriteLine(result[0]);