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
Regex 在C中使用正则表达式删除多个样式标记#_Regex_C# 3.0 - Fatal编程技术网

Regex 在C中使用正则表达式删除多个样式标记#

Regex 在C中使用正则表达式删除多个样式标记#,regex,c#-3.0,Regex,C# 3.0,我有下面的html源代码,它由两个样式标记组成,使用正则表达式我们可以从文件中删除所有html标记,但是我们不能删除第二个样式标记的内容 <style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style> 但我希望样式标记的属性/值也被删除 您可以尝试使用与先前由捕获组匹配的相同文本进行匹配 要删除至的中的所有内容,请使用下面的正则表达式,该正则表达式查找相同的打开和关闭H

我有下面的html源代码,它由两个样式标记组成,使用正则表达式我们可以从文件中删除所有html标记,但是我们不能删除第二个样式标记的内容

<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
但我希望样式标记的属性/值也被删除

您可以尝试使用与先前由捕获组匹配的相同文本进行匹配

要删除
中的所有内容,请使用下面的正则表达式,该正则表达式查找相同的打开和关闭HTML标记

                   <(\w+)[^>]*>.*<\/\1>
Captured Group 1-----^^^             ^^----- Back Reference first matched group
]*>*
捕获的组1------^^^^------返回引用第一个匹配的组

这是

是否要删除样式标记

<style.*?</style>

这有助于从文件中删除所有样式标记。但是我希望样式标记的属性/值也被删除。P{margin top:0;margin bottom:0;}您是否已经测试了它?它确实可以移除。在demo中查看。即使在demo中,它也会留下“P{margin top:0;margin bottom:0;}”。甚至这个也必须删除。那么你想替换html样式标记中的所有内容吗?让我更新我的帖子。
                   <(\w+)[^>]*>.*<\/\1>
Captured Group 1-----^^^             ^^----- Back Reference first matched group
<style.*?</style>