我使用下面的regex模式来识别缩写。你知道吗
mytext = "This is AVGs and (NMN) and most importantly GFD"
mytext= re.sub(r"\b[A-Z\.]{2,}s?\b", "_ABB", mytext)
print(mytext)
我得到如下输出。你知道吗
This is _ABB and (_ABB) and most importantly _ABB
但是,我想得到输出为
This is AVGs_ABB and (NMN_ABB) and most importantly GFD_ABB
请告诉我哪里做错了。你知道吗
使用捕获组捕获要匹配的单词边界之间的模式,然后在替换中使用它。第一个捕获组将作为
\\1
提供。你知道吗Demo of code snippet
替换时使用排除,如下所示:
输出:
This is AVGs_ABB and (NMN_ABB) and most importantly GFD_ABB
试试这个
相关问题 更多 >
编程相关推荐