Regular expression finding empty comments in code

2019-06-02 04:26发布

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!

2条回答
Juvenile、少年°
2楼-- · 2019-06-02 05:06

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.

查看更多
叛逆
3楼-- · 2019-06-02 05:12

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:

Regular expression image

Edit live on Debuggex

查看更多
登录 后发表回答