Regular expression finding empty comments in code

拈花ヽ惹草 提交于 2019-12-08 06:24:35

问题


i am looking for a regular expression which only finds empty java comments like the following one:

/**
 * 
 */

Eclipse creates those when e.g. generating a serial version id... There is another thread about finding all comments however i didn't manage to adapt the regex to only "filter" out the empty ones.

//.*|("(?:\\[^"]|\\"|.)*?")|(?s)/\*.*?\*/

Any ideas? Thanks!


回答1:


Try this:

\/\*\*[\s\t\r\n]*[ \*]*[\s\t\r\n]*\*/

Should match any string which starts with /**, ends with */ and contains only line breaks, spaces or asterisks in between.




回答2:


Wouldn't

"\\s*/[*]{2}[*\\s]*[*]/\\s*"

together with the Pattern.MULTILINE flag suffice?

It starts with whitespace (optional), then comes /** then there is only whitespace and * followed by */ optionally followed by more whitespace.

This is how it looks:

Edit live on Debuggex



来源:https://stackoverflow.com/questions/17471230/regular-expression-finding-empty-comments-in-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!