Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for matching javadoc fragments

This question got me thinking in a regex for matching javadoc comments that include some specified text.

For example, finding all javadoc fragments that include @deprecated:

/**
* Method1
* .....
* @deprecated
* @return
*/

I manage to get to the expression /\*\*.*?@deprecated.*?\*/ but this fails in some cases like:

/**
* Method1
* .....
* @return
*/
public int Method1() { } 

// this method should be @deprecated
public void Method2() { }    

/**
* Method3
* .....
* @return
*/
public int Method3() { } 

where it matches all the code from the 1st javadoc fragment until the 3rd javadoc fragment.

Can someone give a regex for this?

like image 505
bruno conde Avatar asked Mar 27 '09 11:03

bruno conde


1 Answers

Try this one :

/\*\*([^\*]|\*(?!/))*?@deprecated.*?\*/
like image 192
Diadistis Avatar answered Sep 19 '22 17:09

Diadistis