Strip all comments

Discussion in 'HTML' started by KiwiBrian, Jul 22, 2004.

  1. KiwiBrian

    KiwiBrian Guest

    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
     
    KiwiBrian, Jul 22, 2004
    #1
    1. Advertising

  2. KiwiBrian

    Mark Parnell Guest

    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
     
    Mark Parnell, Jul 22, 2004
    #2
    1. Advertising

  3. *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/
     
    Andrew Urquhart, Jul 23, 2004
    #3
  4. KiwiBrian

    Toby Inkster Guest

    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
     
    Toby Inkster, Jul 23, 2004
    #4
  5. *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/
     
    Andrew Urquhart, Jul 23, 2004
    #5
  6. KiwiBrian

    Jeff Thies Guest

    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
     
    Jeff Thies, Jul 23, 2004
    #6
  7. KiwiBrian

    Toby Inkster Guest

    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
     
    Toby Inkster, Jul 23, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CI
    Replies:
    2
    Views:
    2,404
    Soren Kuula
    Jan 11, 2006
  2. Replies:
    0
    Views:
    1,132
  3. Aquila
    Replies:
    35
    Views:
    454
    Mathieu Bouchard
    Mar 31, 2005
  4. yelipolok
    Replies:
    4
    Views:
    263
    John W. Krahn
    Jan 27, 2010
  5. Replies:
    4
    Views:
    611
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page