3

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 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

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:

Regular expression image

Edit live on Debuggex

1 Comment

Thanks for the link to debuggex - din't know that until now. Seems quite helpful especially for a regex padawan like me :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.