Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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中的自动关闭html标记#_C#_Html_Regex - Fatal编程技术网

C# 正则表达式替换c中的自动关闭html标记#

C# 正则表达式替换c中的自动关闭html标记#,c#,html,regex,C#,Html,Regex,我有一个包含一些html标记的xml。当标签出现时,它会打断页面,因为它是一个自动关闭的标签。比如: <iframe width="420" height="315" src="//www.youtube.com/embed/6krfYKxJFqA" frameborder="0" /> 我要替换此文件并将其转换为: 任何人都可以用正则表达式提供c#代码来实现这一点。我试着做: tmp = tmp.Replace("(<iframe[^>]*)(\\s*/>)

我有一个包含一些html标记的xml。当标签出现时,它会打断页面,因为它是一个自动关闭的标签。比如:

<iframe width="420" height="315" src="//www.youtube.com/embed/6krfYKxJFqA" frameborder="0" />

我要替换此文件并将其转换为:

任何人都可以用正则表达式提供c#代码来实现这一点。我试着做:

tmp = tmp.Replace("(<iframe[^>]*)(\\s*/>)", "$1></iframe>");
tmp=tmp.Replace(“(]*)(\\s*/>”),“$1>”;

tmp=newregex(@“(]*)(\\s*/>)”)。替换(tmp,“$1>”);
tmp是包含大量代码的xml+此iframe标记作为字符串


但是没有结果

在第二个正则表达式中,不需要使用双反斜杠


另外,
(]*)
也匹配最后一个
/
,请使用非贪婪的
运算符:
(]*?)(\s*/>)

尝试将此作为匹配表达式:

<iframe(.*?)(["\d\w\s])\/>

在第二个正则表达式中,使用
@
Bravo时不需要双反斜杠。。谢谢这就是问题所在。就知识而言,@造成了什么不同?当然。作为答案发布,请接受..如果我想,如何完全删除iframe标记?@RossCooper使用
]*>
并将其替换为空字符串
“”
<iframe(.*?)(["\d\w\s])\/>