sentence = "Diagnosis: B.
Prostate, Left Lateral Mid, Core Biopsy: - Prostatic adenocarcinoma, Gleason's score 3 3=6/10 - Single focus of carcinoma measures 0.5 mm (involves 1 of 1 core fragment and up to 5% of individual core volume) - Prostatic intraepithelial neoplasia (PIN high grade C.
Prostate, Left Lateral Apex, Core Biopsy: - Prostatic "
Required solution: Diagnosis: Prostate, Left Lateral Mid, Core Biopsy: - Prostatic adenocarcinoma, Gleason's score 3 3=6/10 - Single focus of carcinoma measures 0.5 mm (involves 1 of 1 core fragment and up to 5% of individual core volume) - Prostatic intraepithelial neoplasia (PIN high grade
Prostate, Left Lateral Apex, Core Biopsy: - Prostatic
是否有任何解決方案可以找到單個字母和點,例如:“B”。從句子中洗掉它。我只是對正則運算式感到困惑。我嘗試了一些像 [^A-Za-z]{0,}c[,.;\s]{0,} 這樣的模式模式,但它還不起作用。
uj5u.com熱心網友回復:
你在正確的軌道上使用基于正則運算式的東西。我認為您可以使用re.sub()一個簡單的模式,它需要空格,然后是字母字符和句點。
import re
text = "Diagnosis: B. Prostate, Left Lateral Mid, Core Biopsy: - Prostatic adenocarcinoma, Gleason's score 3 3=6/10 - Single focus of carcinoma measures 0.5 mm (involves 1 of 1 core fragment and up to 5% of individual core volume) - Prostatic intraepithelial neoplasia (PIN high grade C. Prostate, Left Lateral Apex, Core Biopsy: - Prostatic"
pattern = r"\s[a-zA-Z]\."
print(re.sub(pattern, "", text))
那應該給你:
診斷:前列腺,左側中段,核心活檢: - 前列腺腺癌,格里森評分 3 3=6/10 - 單個癌灶尺寸為 0.5 毫米(涉及 1 個核心碎片中的 1 個和高達單個核心體積的 5%)-前列腺上皮內瘤變(PIN 高級別前列腺,左側心尖,核心活檢: - 前列腺
注意“B”。和一個“C” 哪里都洗掉了。我希望這就是你正在尋找的。如果沒有,您可以添加 acount=1作為引數以洗掉“B”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/326727.html
標籤:蟒蛇-3.x
