Monday 29 December 2014

Removing HTML Tags and Java Scripts Tags From String Using Regular Expresion

From today, I am trying to post again on a regular basis

Here is a one line regular expression to remove a html tag from a string.....

In the example given below I am stripping the Script tags from the given string.


      <!--[if IE]>
    <script>
        if (!document.documentMode || (document.documentMode < 9))
        {
            document.write("<script src=\"http://content.jobsdb.com.sg/Content/v184/Javascript/html5.js\"><\/script>");
            document.write("<script src=\"http://content.jobsdb.com.sg/Content/v184/Javascript/html5p.js\"><\/script>");            
            document.write("<style>.job-ad-applytool {text-align: center;}</style>");
        }
    </script>

    <![endif]-->


 First try to remove the Script Tags From String using Below regular expression..

<script>[\d\D]*?>[\d\D]*?</script>     --> this  expression removes script tags from string

eg:-

 Dim _content As String = Regex.Replace(_pageBody.TrimStart(), "<script>[\d\D]*?>[\d\D]*?</script>", "", RegexOptions.Multiline)

later u remove all Html Tags   From string  using Below Regular Expression

<.*?>                       ---->  this expressions remove all html tags..


eg:-

 Dim _content As String  = Regex.Replace(_pageBody.TrimStart(), "<.*?>", "", RegexOptions.Multiline)



it' ll Remove all script tag's and Html Tags From string ...:)





Share:

No comments:

Post a Comment

© TBGsharepointforum All rights reserved | Designed by Blogger Templates