0
我是比較新的python正則表達式。我想在'|'分割一個字符串除了大括號。python正則表達式 - 在'|'處分割一個字符串除了在任何括號內
例子:
Str = " a | (b | c) | d "
我想下面的結果
Result = ["a","(b | c)","d"]
我是比較新的python正則表達式。我想在'|'分割一個字符串除了大括號。python正則表達式 - 在'|'處分割一個字符串除了在任何括號內
例子:
Str = " a | (b | c) | d "
我想下面的結果
Result = ["a","(b | c)","d"]
,你可以嘗試通過'|'
字符 分割字符串轉義括號什麼
Str = " a | (b | c) | d "
a=re.split(r'\|\s*(?![^()]*\))',Str)
print(a)
[' a ', '(b | c) ', 'd ']
如何處理嵌套括號? – deathstroke05