用于匹配 javadoc 片段的正则表达式 [英] Regex for matching javadoc fragments
本文介绍了用于匹配 javadoc 片段的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题让我想到了正则表达式进行匹配javadoc 包含一些指定文本的注释.
This question got me thinking in a regex for matching javadoc comments that include some specified text.
例如,查找包含 @deprecated
的所有 javadoc 片段:
For example, finding all javadoc fragments that include @deprecated
:
/**
* Method1
* .....
* @deprecated
* @return
*/
我设法得到表达式 /**.*?@deprecated.*?*/
但在某些情况下会失败,例如:
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() { }
它匹配从第一个 javadoc 片段到第三个 javadoc 片段的所有代码.
where it matches all the code from the 1st javadoc fragment until the 3rd javadoc fragment.
有人可以为此提供一个正则表达式吗?
Can someone give a regex for this?
推荐答案
试试这个:
/**([^*]|*(?!/))*?@deprecated.*?*/
这篇关于用于匹配 javadoc 片段的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文