Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Regex解析设置值旁边的IP_C#_Regex - Fatal编程技术网

C# Regex解析设置值旁边的IP

C# Regex解析设置值旁边的IP,c#,regex,C#,Regex,我试图从html代码中解析出一个值旁边的IP地址。在html代码中,它如下所示: 范例 X_值_B:192.12.21.31 因此,我希望能够检查X_值_B旁边给出的Ip: 我该如何解析这个呢 这就是我到目前为止所做的: Match m = Regex.Matche(_respStr1, @"\b(\d{1,3}\.){3}\d{1,3}\b", RegexOptions.IgnoreCase); 但是,这并没有特别抓住X_值旁边的Ip。\u B:使用lookback?如果我没弄错,您需要的是

我试图从html代码中解析出一个值旁边的IP地址。在html代码中,它如下所示: 范例

X_值_B:192.12.21.31

因此,我希望能够检查X_值_B旁边给出的Ip:

我该如何解析这个呢

这就是我到目前为止所做的:

Match m = Regex.Matche(_respStr1, @"\b(\d{1,3}\.){3}\d{1,3}\b", RegexOptions.IgnoreCase);

但是,这并没有特别抓住X_值旁边的Ip。\u B:

使用lookback?如果我没弄错,您需要的是

(?!X_Value_B:\s)\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}
那会提取

192.12.21.31

使用这个:

var match = Regex.Match(inputString, 
                    @"X_Value_B:\s*(?<ip>\d+.\d+.\d+.\d+)");

if(match .Success)
    String strIp = match.Groups["ip"].Value;

谢谢如果可以的话,我会在4分钟内进行绿色检查:再次感谢,如果没有,你会得到例外match@burning_LEGION:是的。但这超出了你的问题范围。我更新了我的答案
var match = Regex.Match(inputString, 
                    @"X_Value_B:\s*(?<ip>\d+.\d+.\d+.\d+)");

if(match .Success)
    String strIp = match.Groups["ip"].Value;