[英]How to match complete words for acronym using regex?
我只想從帶有 ( ) 的首字母縮略詞中獲取完整的單詞。
例如,有一句話“肺癌篩查(LCS)降低NSCLC死亡率”; ->結果我想接受“肺癌篩查”。
我怎樣才能用正則表達式做到這一點?
原始問題:我想刪除重復的大寫字母:“HIV acquired immunodeficiency syndrome are at a specially high risk of cervical cancer” => “acquired immunodeficient syndrome are at a particular high risk of cervical cancer”
假設你想定位 2 個或更多大寫字母,我會在這里使用re.sub
:
inp = "Lung cancer screening (LCS) reduces NSCLC mortality"
output = re.sub(r'\s*(?:\([A-Z]+\)|[A-Z]{2,})\s*', ' ', inp).strip()
print(output) # Lung cancer screening reduces mortality
import re
s = 'HIV acquired immunodeficiency syndrome are at a particularly high risk of cervical cancer'
print(re.sub(r'([A-Z])', lambda pat:'', s).strip()) # Inline
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.