Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python正则表达式-在'|';括号内除外_Python_Regex_String_Python 2.7 - Fatal编程技术网

python正则表达式-在'|';括号内除外

python正则表达式-在'|';括号内除外,python,regex,string,python-2.7,Python,Regex,String,Python 2.7,我对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 '] 您可以尝试按“

我对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 ']

您可以尝试按
“|”
字符拆分字符串 转义括号中的任何内容

Str = " a | ( b | c ) | d "
a=re.split(r'\|\s*(?![^()]*\))',Str)
print(a)
[' a ', '( b | c ) ', 'd ']

如何处理嵌套大括号?如何处理嵌套大括号?