正则表达式匹配多组括号之间的所有内容

Regex to match everything between multiple set of brackets

我正在尝试匹配多组括号之间的所有内容

数据示例

[[42.30722,-83.181125],[42.30722,-83.18112667],[42.30722167,-83.18112667,[42.30721667,-83.181125],[+42.30721667,-83.181125]]

我需要匹配内括号内的所有内容,如下所示

42.30722,-83.181125,
42.30722,-83.18112667,
42.30722167,-83.18112667,
42.30721667,-83.181125,
+42.30721667,-83.181125

我该怎么做。我试过 \[([^\[\]]|)*\] 但它给了我带括号的值。谁能帮我解决这个问题。提前致谢

似乎其中一个可能缺少括号,或者如果没有,可能类似于以下表达式:

\[([+-]?\d+\.\d+)\s*,\s*([+-]?\d+\.\d+)\s*\]?

开始可能没问题。

测试

import re

expression = r"\[([+-]?\d+\.\d+)\s*,\s*([+-]?\d+\.\d+)\s*\]?"
string = """
[[42.30722,-83.181125],[42.30722,-83.18112667],[42.30722167,-83.18112667,[42.30721667,-83.181125],[+42.30721667,-83.181125]]
"""

print([list(i) for i in re.findall(expression, string)])
print(re.findall(expression, string))

输出

[['42.30722', '-83.181125'], ['42.30722', '-83.18112667'], ['42.30722167', '-83.18112667'], ['42.30721667', '-83.181125'], ['+42.30721667', '-83.181125']]
[('42.30722', '-83.181125'), ('42.30722', '-83.18112667'), ('42.30722167', '-83.18112667'), ('42.30721667', '-83.181125'), ('+42.30721667', '-83.181125')]

如果您希望 simplify/modify/explore 表达式,regex101.com. If you'd like, you can also watch in this link 的右上面板已对其进行说明,它将如何匹配一些示例输入。


有点晚了,但我想无论如何我都会包括它。

您的第 3 组缺少“]”。

如果在那里,那么在 Alteryx 中,您可以只使用文本到列拆分为行并忽略括号中的定界符