Remove JavaScript code from HTML

I'm looking for a C # regex to replace / remove all JavaScript from HTML. Can someone please help me with the code?

+1


a source to share


2 answers


Deleting just tags <script>

won't actually be done. This is because you can also put Javascript in event handlers (onclick, etc.). They are much more difficult to catch with regex.



Once again, we are revisiting the problem or parsing or processing the HTML with regular expressions. This is the wrong tool for the job. If you don't need brittle code, use an HTML parser.

+5


a source


Why do you want to filter javascript?



If you are trying to prevent cross-site scripting attacks in a web application, you are probably better off using a well-tested library for this purpose. It looks like Microsoft has a library

+3


a source







All Articles