Strip HTML tags ,Script blocks,Forms, style blocks using Regex in C#.net

Share this Article :


Many times in Many cases we may come across this problem how to strip HTML Tags,

How to Remove Script Blocks ? How to remove Form Blocks and how to remove Style sheet blocks ?

for those questions here is the simple and best answer

Strip HTML Tags

to Strip the HTML Tags use the following function,

this will removes the HTML tags from the supplied text

public string StripHTML(string str)

{

return Regex.Replace(str, @\”<(.|\\n)*?>\”, string.Empty);
}

Remove Script Blocks

Usually, removing script blocks is some what tough , but the following function will help you in removing script blocks from the supplied text ,

it will replace the all script blocks with a empty string

public string RemoveScriptblocks(string str)
{
return Regex.Replace(str, @\”@\”, string.Empty);
}

In the same way,

Remove Form Blocks

public string RemoveFormblocks(string str)
{

return Regex.Replace(str, @\”@]*?.*?\”, string.Empty);

}

Written by adrevol

{adrevol has written 91 posts on ITTreats.com . See all posts by }


Leave a Reply