Finding comments using java expressions
I'm working on an expression that finds comments which begin with % and end with \n or \r开发者_Go百科 and also multiple line comments /* */. I'm running into trouble for the one beginning with %. I can get it to detect when the comment starts but it is not terminating with a new line.
"(%.*\\n\\r)|(/\\*(?:.|[\\n\\r])*?\\*/)"
For example, if I have
%hello
nothing nothing nothing
fi
It takes the nothing nothing nothing line as a comment but not the fi line. I'm so confused.
Try this:
((?:%.*?[\\n\\r])|(?:/\\*(?:.|[\\n\\r])*?\\*/))
See here: rubular
Or with Pattern.DOTALL
(?s)((?:%[^\\n\\r]*)|(?:/\\*.*?\\*/))
http://ostermiller.org/findcomment.html
精彩评论