Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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# 正则表达式输入字符串的错误格式不正确_C#_Regex - Fatal编程技术网

C# 正则表达式输入字符串的错误格式不正确

C# 正则表达式输入字符串的错误格式不正确,c#,regex,C#,Regex,嗨,伙计们,我有字符串 我解析它 string population = Regex.Match(content, @"Участники&nbsp;<span class=""clgry"">(?<id>[^""]+?)</span>").Groups["id"].Value; int j = 0; if (!string.IsNullOrEmpty(population)) { log("[+] Группа: " + group + "

嗨,伙计们,我有字符串 我解析它

string population = Regex.Match(content, @"Участники&nbsp;<span class=""clgry"">(?<id>[^""]+?)</span>").Groups["id"].Value;
int j = 0;
if (!string.IsNullOrEmpty(population))
{
    log("[+] Группа: " + group + " Учасники: " + population + "\r\n");
    int population_int = Convert.ToInt32(population);
    if (population_int > 20000)
    {
        lock (accslocker)
        {
        StreamWriter file = new StreamWriter("opened.txt", true);
        file.Write(group + ":" + population + "\r\n");
        file.Close();
    }
    j++;
}
string population=Regex.Match(内容,@“Учаааааааааааааа107;
int j=0;
如果(!string.IsNullOrEmpty(填充))
{
日志(“[+]ГУППаПа:“+组+”Учаааааааааа1072;
int population_int=转换为32(population);
如果(人口>20000)
{
锁(accslocker)
{
StreamWriter文件=新的StreamWriter(“opened.txt”,true);
file.Write(组+”:“+population+”\r\n”);
file.Close();
}
j++;
}
}

但是当我的字符串是
>时,我收到一个选项“输入字符串格式不正确”。

如何避免它?

使用真正的html解析器来解析html,而不是使用正则表达式。(例如,)

string html=@“Учаааааааааааа;
HtmlAgilityPack.HtmlDocument doc=新的HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
var list=doc.DocumentNode.SelectNodes(//span[@class='lnk']/span[@class='clgry']))
.选择(x=>new
{
ParentText=x.ParentNode.FirstChild.InnerText,
Text=x.InnerText
})
.ToList();

使用真正的html解析器来解析html,而不是正则表达式。(例如,)

string html=@“Учаааааааааааааа107;
HtmlAgilityPack.HtmlDocument doc=新的HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
var list=doc.DocumentNode.SelectNodes(//span[@class='lnk']/span[@class='clgry']))
.选择(x=>new
{
ParentText=x.ParentNode.FirstChild.InnerText,
Text=x.InnerText
})
.ToList();

尝试用正则表达式解析html内容不是一个好的决定。看见改用


试图用正则表达式解析html内容不是一个好的决定。看见改用

string html = @"<span class=""lnk"">Участники&nbsp;<span class=""clgry"">59728</span>";
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);

var list = doc.DocumentNode.SelectNodes("//span[@class='lnk']/span[@class='clgry']")
              .Select(x => new
              {
                  ParentText = x.ParentNode.FirstChild.InnerText,
                  Text = x.InnerText
              })
              .ToList();
var spans = doc.DocumentNode.Descendants("span")
               .Where(s => s.Attributes["class"].Value == "clgry")
               .Select(x => x.InnerText)
               .ToList();