Strip all comments

K

KiwiBrian

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
 
M

Mark Parnell

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

Andrew Urquhart

*Mark Parnell* said:
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!
 
T

Toby Inkster

Andrew said:
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 -- >
 
A

Andrew Urquhart

*Toby Inkster* said:
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)
 
J

Jeff Thies

Andrew said:
*Toby Inkster* said:
Andrew Urquhart wrote:



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
 
T

Toby Inkster

Andrew said:
*Toby Inkster* said:
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 --
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top