Sublime text 2 how to delete comments only

前端 未结 6 1902
既然无缘
既然无缘 2020-12-23 12:30

In my sass code, I have inline comments and I wish to remove these in sublime text. Is it possible to permanently delete all comment content alone?

@functio         


        
6条回答
  •  抹茶落季
    2020-12-23 13:26

    You'll need to double check this (have a backup handy!), but the following regular expression should work in the "replace" window, with regular expressions enabled (the * icon):

    1. Open the "replace" window (ctrl + h / cmd + option + f)
    2. Enable regular expression matching by making sure the * icon is selected
    3. Enter the following in the "Find What?" box

      \/\/.*
      
    4. Leave the "replace with" box empty to delete found text.

    5. Click "Replace All"

    Edit

    as @ollie noted, this also will delete any urls prefixed with //. The following (lightly tested) regex should serve to better target comments: (^\/\/.*)|(\s+\/\/.*)

    Edit v2

    A solution for single and multi-line comments (^\/\/.*)|(\s+\/\/.*)|((\/\*)(.|\n)+?(\*\/))

提交回复
热议问题