Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Strip all comments

Reply
Thread Tools

Strip all comments

 
 
KiwiBrian
Guest
Posts: n/a
 
      07-22-2004
I have a need to remove all comments from html files.
Is there a program/utility/application that will do this?

Alternatively/additionally is there a way of deleting many strings which
have the first few, and last few characters the same, but different
filenames referenced within the string?

Thanks
Brian Tozer


 
Reply With Quote
 
 
 
 
Mark Parnell
Guest
Posts: n/a
 
      07-22-2004
On Fri, 23 Jul 2004 08:30:46 +1200, KiwiBrian <>
declared in alt.html:

> I have a need to remove all comments from html files.


I'm sure it could be done easily with regular expressions, but I'm
clueless when it comes to them. Someone else should be able to push
you in the right direction though.

--
Mark Parnell
http://www.clarkecomputers.com.au
"Never drink rum&coke whilst reading usenet" - rf 2004
 
Reply With Quote
 
 
 
 
Andrew Urquhart
Guest
Posts: n/a
 
      07-23-2004
*Mark Parnell* wrote:
> On Fri, 23 Jul 2004 08:30:46 +1200, KiwiBrian <>
> declared in alt.html:
>
>> I have a need to remove all comments from html files.

>
> I'm sure it could be done easily with regular expressions, but I'm
> clueless when it comes to them. Someone else should be able to
> push you in the right direction though.


E.g. Open TextPad, open the 'Find In Files' dialogue, enter
'<!--[^#]?[^--]*-->' minus quotes in the 'Find what' input box, tick
'Regular expression', choose appropriate file type and folder, run
'Find'. In generated results pane, bring up context menu and choose
'Open all'. Open 'Replace' dialogue (CTRL-H), write
'[\t ]*<!--[^#]?[^--]*-->[\t ]*\n?' in the 'Find what' box minus quotes,
tick 'All documents', run 'Replace All'. Check all open documents for
any mis-matches, errors, choose 'save all' menu option in file menu.

Regular expressions delete <!--anything--> but ignore lines with a #
after the comment <!--#anything--> to prevent deleting SSI declarations.
Back-up files before use!
--
Andrew Urquhart
- My reply address is invalid, see www.andrewu.co.uk/contact/


 
Reply With Quote
 
Toby Inkster
Guest
Posts: n/a
 
      07-23-2004
Andrew Urquhart wrote:

> Regular expressions delete <!--anything--> but ignore lines with a #
> after the comment <!--#anything--> to prevent deleting SSI declarations.
> Back-up files before use!


Though your regexp fails to match this valid comment:

<!-- I am a valid comment -- >

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 
Reply With Quote
 
Andrew Urquhart
Guest
Posts: n/a
 
      07-23-2004
*Toby Inkster* wrote:
> Andrew Urquhart wrote:
>
>> Regular expressions delete <!--anything--> but ignore lines with a #
>> after the comment <!--#anything--> to prevent deleting SSI
>> declarations. Back-up files before use!

>
> Though your regexp fails to match this valid comment:
>
> <!-- I am a valid comment -- >


Then I suggest you insert [\t ]* in the appropriate location

([\t ] as for some reason Textpad doesn't understand \s)
--
Andrew Urquhart
- My reply address is invalid, see www.andrewu.co.uk/contact/


 
Reply With Quote
 
Jeff Thies
Guest
Posts: n/a
 
      07-23-2004
Andrew Urquhart wrote:

> *Toby Inkster* wrote:
>
>>Andrew Urquhart wrote:
>>
>>
>>>Regular expressions delete <!--anything--> but ignore lines with a #
>>>after the comment <!--#anything--> to prevent deleting SSI
>>>declarations. Back-up files before use!

>>
>>Though your regexp fails to match this valid comment:
>>
>><!-- I am a valid comment -- >

>
>
> Then I suggest you insert [\t ]* in the appropriate location
>
> ([\t ] as for some reason Textpad doesn't understand \s)


I was wondering what that was for!

Jeff
 
Reply With Quote
 
Toby Inkster
Guest
Posts: n/a
 
      07-23-2004
Andrew Urquhart wrote:

> *Toby Inkster* wrote:
>> Andrew Urquhart wrote:
>>
>>> Regular expressions delete <!--anything--> but ignore lines with a #
>>> after the comment <!--#anything--> to prevent deleting SSI
>>> declarations. Back-up files before use!

>>
>> Though your regexp fails to match this valid comment:
>>
>> <!-- I am a valid comment -- >

>
> Then I suggest you insert [\t ]* in the appropriate location
> ([\t ] as for some reason Textpad doesn't understand \s)


Don't forget \r and \n.

<!-- I am another valid comment --
>


--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Now Playing ~ ./james/the_best_of_james/18_hymn_from_a_village.ogg

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strip all but second second line from bottom and then strip that!!!! yelipolok Perl Misc 4 01-27-2010 08:14 AM
How to strip ruby comments in a ruby line of code? Alexandre Mutel Ruby 16 11-19-2009 04:55 PM
How to strip comments out of code silviocortes@yahoo.com Java 19 11-02-2007 08:06 AM
Strip comments from XML documents CI XML 2 01-11-2006 11:18 PM
strip and its evil brother strip! Aquila Ruby 35 03-31-2005 04:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57