更新时间:2022-10-20 22:56:17
试试这个正则表达式在 eclipse/sed/你最喜欢的支持正则表达式的编辑器中搜索替换.
/**(?s:(?!*/).)**/
?s
将输入视为单行**
*/
的负前瞻*/
编辑
要解决字符串包含 javadoc 的情况,请使用此正则表达式
((?<!\)"([^"]|(?<=\)")*")|(/**(?s:(?!*/).)**/)
并用第一个捕获组替换它
/1
那么如果你说这不应该匹配
///** */
或更复杂的情况
我建议,使用像 antlr 这样的解析器工具来使用
/**(?:(?!*/).)**/
Is there any tool / Eclipse plugin that can remove all JavaDoc comments in a file?
The normal (non-JavaDoc) comments should be intact after running the tool.
Try this regex to search replace either in eclipse / sed / your favorite editor that has regex support.
/**(?s:(?!*/).)**/
?s
treat input as single line**
*/
*/
Edit
To tackle cases where strings containing javadoc, use this regex
((?<!\)"([^"]|(?<=\)")*")|(/**(?s:(?!*/).)**/)
and replace it with first capture group
/1
Then if you say this shouldn't match
///** */
or more complex cases
I suggest, using a parser tool like antlr to parse using java grammar for tokens like comments and strings and remove elements that you don't want
Sometime I find my own regex answers cryptic !!
So here is some visual feedback
((?!\)"([^"]|(?=\)")*")|(/**(?:(?!*/).)**/)
/**(?:(?!*/).)**/