I am trying to write a regular expression which finds all the comments in text.
For example all between /* */
.
Example:
/* Hello */
Unlike the example posted above, you were trying to match comments that spanned multiple lines. By default, .
does not match a line break. Thus you have to enable multi-line mode in the regex to match multi-line comments.
Also, you probably need to use .*?
instead of .*
. Otherwise it will make the largest match possible, which will be everything between the first open comment and the last close comment.
I don't know how to enable multi-line matching mode in Sublime Text 2. I'm not sure it is available as a mode. However, you can insert a line break into the actual pattern by using CTRL + Enter. So, I would suggest this alternative:
/\*(.|\n)*?\*/
If Sublime Text 2 doesn't recognize the \n
, you could alternatively use CTRL + Enter to insert a line break in the pattern, in place of \n
.