Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.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# 正则表达式带跨度标签_C#_Regex - Fatal编程技术网

C# 正则表达式带跨度标签

C# 正则表达式带跨度标签,c#,regex,C#,Regex,我想去掉Span标记的html字符串 我有一个html字符串: <a href=\"http://www.dr.dk/roskilde\"><span>Roskilde</span><span>Festival</span></a> 我要把它简化为:罗斯基尔节 Atm,我有一个正则表达式字符串,它应该能够找到所有的span标记,但它失败了 System.Collections.Specialized.StringCo

我想去掉Span标记的html字符串

我有一个html字符串:

<a href=\"http://www.dr.dk/roskilde\"><span>Roskilde</span><span>Festival</span></a>

我要把它简化为:罗斯基尔节

Atm,我有一个正则表达式字符串,它应该能够找到所有的span标记,但它失败了

 System.Collections.Specialized.StringCollection sc = new System.Collections.Specialized.StringCollection();

    sc.Add(@"/<\s*\/?\s*span\s*.*?>/g");


    foreach (string s in sc)
    {
        k = System.Text.RegularExpressions.Regex.Replace(pContent, s, "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    }
    k = System.Text.RegularExpressions.Regex.Replace(pContent, @"&nbsp;", @"&#160;");                                                              
System.Collections.Specialized.StringCollection sc=new System.Collections.Specialized.StringCollection();
sc.Add(@“//g”);
foreach(sc中的字符串s)
{
k=System.Text.RegularExpressions.Regex.Replace(pContent,s,“,System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}
k=System.Text.RegularExpressions.Regex.Replace(pContent,@“@“ ;”);
有什么想法吗


另外,我不认为使用Html Agility Pack不是处理Html的最佳方法。使用理解嵌套的HTML解析器,因为Regexp不理解HTML嵌套

考虑查看反向字符集,即
]*>

我猜您是从某个地方复制的,但是您的regexp可能不是正确的C#语法(额外的
/
/g
)。重新阅读C#教程中的regexp!请尝试以下字符串:

Example /<span>/g does this tag get removed?
Example//g是否删除了此标记?
您可能打算使用的是:

sc.Add(@"</?span( [^>]*|/)?>");
sc.Add(@“]*|/)?>”;

Regexp不是处理HTML的最佳方法。使用理解嵌套的HTML解析器,因为Regexp不理解HTML嵌套

考虑查看反向字符集,即
]*>

我猜您是从某个地方复制的,但是您的regexp可能不是正确的C#语法(额外的
/
/g
)。重新阅读C#教程中的regexp!请尝试以下字符串:

Example /<span>/g does this tag get removed?
Example//g是否删除了此标记?
您可能打算使用的是:

sc.Add(@"</?span( [^>]*|/)?>");
sc.Add(@“]*|/)?>”;

你能考虑替换吗?为什么你不想使用HTML敏捷包?它的CuStuMMER特定需求你能考虑替换吗?为什么不想使用HTML敏捷包?