Python 如何从javadoc注释中删除@link标记及其在{和}之间的内容?
我试图分析Javadoc注释。我不需要@link标签的内容。我怎样才能删除这个? 一般格式为{@link………} 使用下面的代码,我得到一个错误:ValueError:字段名中意外的“{” 输入:Python 如何从javadoc注释中删除@link标记及其在{和}之间的内容?,python,regex,javadoc,Python,Regex,Javadoc,我试图分析Javadoc注释。我不需要@link标签的内容。我怎样才能删除这个? 一般格式为{@link………} 使用下面的代码,我得到一个错误:ValueError:字段名中意外的“{” 输入: /** * Adds the specified source and target vertices to the graph, if not already included, and * creates a new edge and adds it to the specifie
/**
* Adds the specified source and target vertices to the graph, if not already included, and
* creates a new edge and adds it to the specified graph similarly to the
* {@link Graph#addEdge(Object, Object)} method.
* {@code sourceVertex}
* @param graph the graph for which the specified edge to be added
* @param sourceVertex source vertex of the edge
* @param targetVertex target vertex of the edge
* @param <V> the graph vertex type
* @param <E> the graph edge type
*
* @return The newly created edge if added to the graph, otherwise <code>
* null</code>.
*/
输出
/**
* Adds the specified source and target vertices to the graph, if not already included, and
* creates a new edge and adds it to the specified graph similarly to the
* method.
*
* {@code sourceVertex}
* @param graph the graph for which the specified edge to be added
* @param sourceVertex source vertex of the edge
* @param targetVertex target vertex of the edge
* @param <V> the graph vertex type
* @param <E> the graph edge type
*
* @return The newly created edge if added to the graph, otherwise <code>
* null</code>.
*/
Sipmly作为:
import re
input = """/**
* Adds the specified source and target vertices to the graph, if not already included, and
* creates a new edge and adds it to the specified graph similarly to the
* {@link Graph#addEdge(Object, Object)} method.
*
* @param graph the graph for which the specified edge to be added
* @param sourceVertex source vertex of the edge
* @param targetVertex target vertex of the edge
* @param <V> the graph vertex type
* @param <E> the graph edge type
*
* @return The newly created edge if added to the graph, otherwise <code>
* null</code>.
*/"""
out = re.sub('{@link.*?}', '', input)
输出:
/**
* Adds the specified source and target vertices to the graph, if not already included, and
* creates a new edge and adds it to the specified graph similarly to the
* method.
*
* @param graph the graph for which the specified edge to be added
* @param sourceVertex source vertex of the edge
* @param targetVertex target vertex of the edge
* @param <V> the graph vertex type
* @param <E> the graph edge type
*
* @return The newly created edge if added to the graph, otherwise <code>
* null</code>.
*/
也许只需删除_link_tag=re.subr'\s*{@link[^{}]*}“,第行?@WiktorStribiżew谢谢,但是你能用需要删除的内容发布你的答案吗。这里有点混乱:你是在把修改过的内容写回另一个/同一个文件吗?你的代码真的很混乱。@AlyssaAlex代码更新”done@WiktorStribiżew打印结果或将结果写回文件是否重要?嘿,谢谢,sorr由于不清楚,我只是更新了我的问题。我不想丢失{@code….}标记之间的内容,只需将@link添加到re.sub中即可
/**
* Adds the specified source and target vertices to the graph, if not already included, and
* creates a new edge and adds it to the specified graph similarly to the
* method.
*
* @param graph the graph for which the specified edge to be added
* @param sourceVertex source vertex of the edge
* @param targetVertex target vertex of the edge
* @param <V> the graph vertex type
* @param <E> the graph edge type
*
* @return The newly created edge if added to the graph, otherwise <code>
* null</code>.
*/