我正在尝试解析html代码中值旁边的IP地址。在html代码中,它看起来像这样: 示例
X_Value_B:192.12.21.31
所以我希望能够检查X_Value_B旁边给出的Ip:
我如何解析这个?
这是我到目前为止所做的:
Match m = Regex.Matche(_respStr1, @"\b(\d{1,3}\.){3}\d{1,3}\b", RegexOptions.IgnoreCase);
然而,这并没有特别抓住X_Value_B旁边的Ip:
答案 0 :(得分:0)
使用lookbehind (?<=)
f.e。 (?<=X_Value_B:\s*)(\d{1,3}\.){3}\d{1,3}
答案 1 :(得分:0)
如果我找对你,你需要的是
(?!X_Value_B:\s)\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}
那将提取
192.12.21.31
这
X_Value_B: 192.12.21.31
答案 2 :(得分:0)
使用这个:
var match = Regex.Match(inputString,
@"X_Value_B:\s*(?<ip>\d+.\d+.\d+.\d+)");
if(match .Success)
String strIp = match.Groups["ip"].Value;