我有这个字符串:
{"TimePeriod": {"Start": "2017-03-01", "End": "2017-04-01"}, "Total": {"UnblendedCost": {"Amount": "2942.25119998", "Unit": "USD"}, "UsageQuantity": {"Amount": "20835", "Unit": "Hrs"}}, "Groups": [], "Estimated": false},
{"TimePeriod": {"Start": "2017-04-01", "End": "2017-05-01"}, "Total": {"UnblendedCost": {"Amount": "2982.62609983", "Unit": "USD"}, "UsageQuantity": {"Amount": "21049", "Unit": "Hrs"}}, "Groups": [], "Estimated": false},
{"TimePeriod": {"Start": "2017-05-01", "End": "2017-06-01"}, "Total": {"UnblendedCost": {"Amount": "1399.04829988", "Unit": "USD"}, "UsageQuantity": {"Amount": "23010", "Unit": "Hrs"}}, "Groups": [], "Estimated": false},
{"TimePeriod": {"Start": "2017-06-01", "End": "2017-07-01"}, "Total": {"UnblendedCost": {"Amount": "962.47549987", "Unit": "USD"}, "UsageQuantity": {"Amount": "20049", "Unit": "Hrs"}}, "Groups": [], "Estimated": false}
我正在使用正则表达式将上述字符串拆分为多条记录,例如:每条记录如下所示:
{"TimePeriod": {"Start": "2017-06-01", "End": "2017-07-01"}, "Total": {"UnblendedCost": {"Amount": "962.47549987", "Unit": "USD"}, "UsageQuantity": {"Amount": "20049", "Unit": "Hrs"}}, "Groups": [], "Estimated": false}
我目前的做法是
(\{\"TimePeriod\":){1}.+(false\}){1}
但这将匹配整个字符串而不是匹配每条记录,我认为解决方案应该是正则表达式中的前瞻,以确保TimePeriod在匹配的字符串中只出现一次,但我不知道该怎么做。任何指针将不胜感激。
*每行之间没有换行符,我只是把它放在那里进行演示