Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to remove all comments from CSS file in Sublime Text 2

I am in need of a Sublime Text 2 friendly regex that would allow me to search for all comments within a file.

The comments are all following this basic structure /* <anything> */

Thanks for taking the time to help :)

like image 675
Mad-Chemist Avatar asked Feb 28 '14 21:02

Mad-Chemist


2 Answers

Search for:

(?s)/\*.*?\*/

This allows you to match comments that spreads over multiple lines.

The (?s) turns on "single line" mode, which makes . matches any character without exception (by default, . excludes line separators).

This assumes that there is no /* or */ inside a string literal.

Or if you want a bullet-proof solution, you may want to take a look at this question:

Can we make use of syntax highlighting feature to remove all comments from a source file in SublimeText?

like image 157
nhahtdh Avatar answered Nov 15 '22 01:11

nhahtdh


Something like this should work:

\/\*.+?\*\/

I'm not super-familiar with Sublime Text, but this would work in Notepad++, and I believe the regex implementation is basically the same. If I'm wrong, feel free to let me know.

Edit: Per CAustin's helpful tip, you can also just do this (without the escaping of the forward slashes):

/\*.+?\*/
like image 20
elixenide Avatar answered Nov 15 '22 00:11

elixenide