Wednesday, July 24, 2013

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]>
        if (!document.documentMode || (document.documentMode < 9))
            document.write("<script src=\"\"><\/script>");
            document.write("<script src=\"\"><\/script>");            
            document.write("<style>.job-ad-applytool {text-align: center;}</style>");


 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


 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..


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

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

No comments:

Post a Comment