Skip to content

Instantly share code, notes, and snippets.

@DLMousey
Last active March 21, 2017 10:37
Show Gist options
  • Save DLMousey/7ad9e0efeccfb5d673f08c0648f106c9 to your computer and use it in GitHub Desktop.
Save DLMousey/7ad9e0efeccfb5d673f08c0648f106c9 to your computer and use it in GitHub Desktop.
Useful Regex Snippets

General use method

In sublime & VS Code when you enter find and replace (CTRL + H on windows, I think CMD + H on mac?) there's a toggle switch with .* on it, This will enable regex searching which when enabled, Will allow you to use these snippets

HTML Comment Removal

Remove erronous comments that prevent you from commenting out a block of HTML code. For instance a block like this would prevent you from commenting out anything after it because the existing comment will interrupt the new comment tags that will surround the content;

    <div class="foo">
        <li class="bar">Baz</li>
    </div>
    <!-- ./foo -->

This snippet will remove any and all HTML Comments in a document - Use with care. The additional brackets surrounding it may or may not be required, Doesn't seem to matter either way

(<!--(.*)-->)

HTML Blank Line Removal

Remove empty lines that would be left behind by running the comment removal regex, They're both annoying and time consuming to remove, Regex to the rescue! This will search for lines that have a carriage return or a new line character at the very start of them and nothing after that. This will remove all blank lines from a document, Against use with care.

^[\n\r]+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment