Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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_Json - Fatal编程技术网

在python中删除字符串中的特定模式

在python中删除字符串中的特定模式,python,json,Python,Json,我有以下json字符串: {"date":12455} {"date":12455,"out_date":45677} {"date":Date(12455),"out_date":45677} #invalid json because of Date(...) {"date":12455,"out_date":45677,"other_date":12345} #valid json because of Date(...) {"date":12455,"foo":"bar"} {"date

我有以下json字符串:

{"date":12455}
{"date":12455,"out_date":45677}
{"date":Date(12455),"out_date":45677} #invalid json because of Date(...)
{"date":12455,"out_date":45677,"other_date":12345} #valid json because of Date(...)
{"date":12455,"foo":"bar"}
{"date":12455,"out_date":Date(45677),"other_date":Date(12345)} #invalid json because of Date(...)
所以基本上,我在一些字符串中有这个“Date(…)”字段。 不是所有的字符串都有。 有些字符串多次使用它

除了“替换(…)”之外,还有没有更好的方法替换其中的所有“日期(…)”。。 比如说

{"date":12455,"out_date":Date(45677),"other_date":Date(12345)} becomes:
{"date":12455,"out_date":45677,"other_date":12345}

基本上,我想将这些json转换为有效的json

使用
日期生成输出的是什么?看来你应该解决这个问题。另外,您确定不想以某种方式使用
Date
,而不只是删除该部分吗?@ExplosionPills Well。。这是我从公共api获得的数据。。所以我已经提交了报告。。不我只想解析这些JSON,用
Date
生成输出的是什么?看来你应该解决这个问题。另外,您确定不想以某种方式使用
Date
,而不只是删除该部分吗?@ExplosionPills Well。。这是我从公共api获得的数据。。所以我已经提交了报告。。不我只想解析这些json
In [1]: import re

In [7]: re.sub("Date\((.+?)\)",r"\1",'{"date":Date(12455),"out_date":45677}')
Out[7]: '{"date":12455,"out_date":45677}'
re.sub(r"Date\((.*?)\)", r"\1", input)