Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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:Port匹配_C#_Regex - Fatal编程技术网

C# Regex与Ip:Port匹配

C# Regex与Ip:Port匹配,c#,regex,C#,Regex,我有下面的正则表达式来匹配Ip:Port表单html代码,但出于某种原因,我只返回了第一个匹配项,然后它就停止了 我的代码: Match m = Regex.Match(_theHtmlCode, @"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,8}\b", RegexOptions.IgnoreCase); if (m.Success) { if(m.Groups[0].Value !=

我有下面的正则表达式来匹配Ip:Port表单html代码,但出于某种原因,我只返回了第一个匹配项,然后它就停止了

我的代码:

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

       if (m.Success)
       {
           if(m.Groups[0].Value != "")
           {
               resultsFound.Add(m.Groups[0].Value);
           }

       }

您知道如何将所有匹配项添加到resultsFound中吗?

您需要使用
Regex.matches
方法,而不是
Regex.Match
方法。这将返回一个
MatchCollection
而不是单个
Match
,其中集合包含正则表达式的所有匹配项。

您需要使用
Regex.matches
方法,而不是
Regex.Match
方法。这将返回一个
MatchCollection
,而不是单个
Match
,该集合包含正则表达式的所有匹配项。

var m=Regex.matches(\u theHtmlCode,@“\b(\d{1,3}){3}\d{1,3}\:\d{1,8}\b”,RegexOptions.IgnoreCase)

这个regex可能会得到错误的ip,这个只匹配真实ip,这个只匹配真实ip,这个这个regex可能会得到错误ip,这个只匹配真实ip:<代码>((25[0-5-0-5[0-5[0-5)这个regex可能会得到错误ip,这个只匹配错误ip,这个只匹配真实ip:<代码>((25[0-0-5[0-0-5]0-5[0-5[0-5[0-5[0-5[0-5[0-5[0-5[0-5]2[0-5[0-5]2[0-0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4[0-4]0-),
这个正则表达式可能会得到错误的ip,它只匹配真正的ip:
((25[0-5][0-4][0-9][01]?[0-9][0-9][0-9]?)\){3}(25[0-5][2[0-4][0-9][01]?[0-9][0-9]):\d+

噢,我修改后的代码与匹配时会是什么样子?当我切换到matches和MatchCollection时,到处都会出现错误获取
MatchCollection
并使用
foreach(匹配中的var m)
对其进行迭代。在外观中,保留您的
if(m.Success)
block.Ohh,我修改的代码与匹配项的外观如何?当我切换到matches和MatchCollection时,到处都会出现错误获取
MatchCollection
并使用
foreach(匹配中的var m)
对其进行迭代。在外观内部,保留
if(m.Success)
块。