Regular Expression for Extracting Script Tags

前端 未结 2 796
慢半拍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: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:

    ";
    
    

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

提交回复
热议问题