我早些时候发布了一个问题,但不清楚它是否很清楚,因此再次出现:
我有一个看起来像这样的字符串:
{
"1000":[ [some whitespace and nonwhitespace characters],
[some whitespace and nonwhitespace characters],
....
[some whitespace and nonwhitespace characters]],
"1001":[ [some whitespace and nonwhitespace characters],
[some whitespace and nonwhitespace characters],
....
[some whitespace and nonwhitespace characters]],
...
}
我想使用regex提取如下所示的记录:
"1000":[ [some whitespace and nonwhitespace characters],
[some whitespace and nonwhitespace characters],
....
[some whitespace and nonwhitespace characters]]
我正在使用re模块在python中执行此操作
现在我想到了这个模式:
' "[0-9]{4}":(anything except ]] ) '
但我无法弄清楚除[]]外的任何事物的模式是什么
有人可以帮忙吗?
regex解决方案可以使用以下方法实现:
\d{4}":(.*?)]]
但你真的不希望,如果你的字符串是一个有效的JSON在这里使用正则表达式。Python使用JSON很自然。假设您的数据是:
data = {key1: [[str1], [str2], ...], ...}
您可以key1
通过访问相应的密钥来简单地获取的值:
data[key1]
这将为您提供:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句