(?ms)^\s*([^\-/\s][^;]+;)((?:(?:\s+/\*(?:.(?!\*/))+.\*/)|(?:\s+\-\-[^\r\n]+))*)
should do it nicely.
(Note: (?ms)
is the way in Java to specify a "multi-line" "dot-all" mode, but I have tested in on RETester and it works)
It can detect 0 or more comments after the select
.
Multi line comments are accepted between /*
and */
because of the use of a positive lookahead (?:.(?!\*/))+
in a non-capturing group
Update: modified it to detect any "non-comment" line before 0 or many comments.
To detect comment1, then statement, then comments:
(?ms)((?:(?:\s+/\*(?:.(?!\*/))+.\*/)|(?:\s+\-\-[^\r\n]+))*)\s*^\s*([^\-/\s][^;]+;)((?:(?:\s+/\*(?:.(?!\*/))+.\*/)|(?:\s+\-\-[^\r\n]+))*)
Note: I have update in both regexps (the one in the beginning and this one) the statement detection part:
\s*([^\-/][^;]+;)
to
\s*([^\-/\s][^;]+;)
Note bis: only the first "comments - statement - comments
" will be detected.
The next blocks will also be detected, but only as : "statement - comments
", then "statement - comments
", and so on. (the comments above a statement are part of the comments below the previous statement)