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 :)
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?
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):
/\*.+?\*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With