The reason your only one-line comments are because of the typical regular expressions .
matches anything other than newlines; while the other uses a negative character class that matches any other than the specified characters, and therefore can match newline characters.
However, if you fix it (usually there is an option for multiline or “as if one line” match), you will find that it will match /*
first comment to */
last comment; will you need to use a non-greedy quantifier,. .*?
to match no more than one comment.
However, the more complex regular expression you give is even more complex. Based on nikc.org's answer, I believe that it should provide a restriction that “comments may not be nested”; that is, they should not contain /*
inside them. In other languages that allow you to comment on /* like /* this */
(i.e., Inner / * is not forbidden or a nested comment), the template \/\*.*?\*\/
Would be appropriate to match them.
source share