提取脚本标记的正则表达式 [英] Regular Expression for Extracting Script Tags

查看:115
本文介绍了提取脚本标记的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写在C#中的正则表达式来删除所有脚本标记及其中包含的任何

I am trying to write a regular expression in C# to remove all script tags and anything contained within them.

到目前为止,我想出了以下内容: \≤([^:] *?:) script\> [^(\< /≤([^:??] * :) script\>) ?] * \< / script\方式> ,但是这不工作

So far I have come up with the following: \<([^:]*?:)?script\>[^(\</<([^:]*?:)?script\>)]*?\</script\>, however this does not work.

我要打破它,并解释我的思想在每一节:

I'll break it up and explain my thinking in each section:

\<([^:]*?:)?script\>



在这里,我想指出,这应该得到任何脚本元素,哪怕是带有前缀命名空间,比方说,< A:脚本>< / A:脚本> 我也已将此添加到结束标记

Here I am trying to state that it should get any script element, even if it is prefixed with a namespace, say, <a:script></a:script>. I have also added this to the closing tag.

[^(\</<([^:]*?:)?script\>)]*?



在这里,我想指出,它应该允许任何标签内包含除< / A:脚本> < / SCRIPT>

\</script\>



在这里,我指出它应该有一个关闭标签。

Here I am stating that it should have a closing tag.

任何人都可以找出我要去的地方错了。

Can anyone spot where I am going wrong?

推荐答案

你不能用正则表达式解析HTML。

使用 HTML敏捷性包的吧。

这篇关于提取脚本标记的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆