开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜