开发者

Finding comments using java expressions

开发者 https://www.devze.com 2023-03-04 21:20 出处:网络
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

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

精彩评论

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

关注公众号