Regular Expression for Extracting Script Tags

前端 未结 2 791
慢半拍i
慢半拍i 2020-12-06 19:20

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

So far I have come up with the following: \\<(

相关标签:
2条回答
  • 2020-12-06 19:28

    You can't parse HTML with regular expressions.

    Use the HTML Agility Pack instead.

    0 讨论(0)
  • 2020-12-06 19:47

    This regular expression does the trick just fine:

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

    But don't do it please

    You will run into a problem by this simple HTML:

    <script>
    var s = "<script></script>";
    </script>
    

    How are you going to solve this problem? It is smarter to use the HTML Agility Pack for such things.

    0 讨论(0)
提交回复
热议问题