我想刪除括號和駐留在這些括號中的文本以及連字符。一些字符串示例如下所示:
example = 'Year 1.2 Q4.1 (Section 1.5 Report (#222))'
example2 = 'Year 2-7 Q4.8 - Data markets and phases' ##there are two hyphens
如何從Python字符串中刪除括號內的文本?
我想結果是:
example = 'Year 1.2 Q4.1'
example2 = 'Year 2-7 Q4.8'
如何刪除文本居住之中或之後的括號內的特殊字符?我只能找到str.strip()
方法。我是Python的新手,所以任何反饋都非常感謝!
方法有很多種。你應該看看用正則表達式來做。我用正則表達式標記它,很快正則表達式鯊魚將在這裏。 –
[Python:按分隔符列表拆分字符串]的可能重複(https://stackoverflow.com/questions/4697006/python-split-string-by-list-of-separators) – splash58
@AntonvBR lol。正則表達式的鯊魚正在水中盤旋 –