Click to See Complete Forum and Search --> : Removing HTML comments


Sean
09-09-2002, 07:12 AM
Greetings all,

Just wanted to know, does visual studio .net have a tool that will strip
out all of the HTML comments from an aspx page.

Cheers

Sean

Phil Weber
09-12-2002, 05:37 AM
> Does Visual Studio .NET have a tool that will strip out
> all of the HTML comments from an aspx page?

Sean: You can use VS.NET's search-and-replace function to do this: In the
Replace dialog, select "Use: Regular Expressions", then search for
"\<!--(.+)--\>" (without the quotes) and replace with nothing.
--
Phil Weber

Russell Jones
09-13-2002, 11:13 AM
You can use the RegEx class to do this in code as well. For example, the
following code finds all the HTML comments in the string s, and removes
them, along with any trailing carriage-return/line feed combinations.

Dim aMatch As Match
Dim pattern As String = "((<!--)((?!<!--).)*(-->))(\r\n)*"
Dim re As New Regex(pattern, RegexOptions.Singleline)
Dim s As String = "<html>" & System.Environment.NewLine & _
"<head><title>Test Document</title></head>" & System.Environment.NewLine
& _
"<body>" & System.Environment.NewLine & _
"<!-- this is a comment -->" & System.Environment.NewLine & _
"This is some content" & System.Environment.NewLine & _
"<!--" & System.Environment.NewLine & _
"<div>This is some more content</div>-->" & System.Environment.NewLine &
System.Environment.NewLine & _
"</body>" & System.Environment.NewLine & _
"</html>"
Debug.WriteLine("Before replacing comments: " & System.Environment.NewLine &
s)
Debug.WriteLine("")
s = re.Replace(s, pattern, "", RegexOptions.Singleline)
Debug.WriteLine("After replacing comments: " & s)


"Sean" <sean_tolram@uk.ibm.com> wrote in message
news:3d7c821c$1@10.1.10.29...
>
> Greetings all,
>
> Just wanted to know, does visual studio .net have a tool that will strip
> out all of the HTML comments from an aspx page.
>
> Cheers
>
> Sean

Burt
09-19-2002, 10:41 AM
why must one specify the pattern and the RegexOption twice when doing the
replace?

Where might one find a reference of the Regular expression pattern characters?

Phil Weber
09-19-2002, 06:42 PM
> Where might one find a reference of the regular
> expression pattern characters?

Burt: Look in VS.NET's online help index under "regular expressions, syntax", or
visit http://shorterlink.com/?TL0FZW
--
Phil Weber