Test='{" addtimes ":" 2019:01:01 12:12:20 ", "product" : "apple", "price" : "26.00"}, {" addtimes ":" 2019: a 01:02 08:05:00 ", "product" : "mango", "price" : "18.00"}, {" addtimes ":" 2019: a 02:02 09:06:05 ", "product", "banana", "price" : "16.00"}'
The pattern=re.com running (
R '" addtimes ":" (\ d {4} : \ d {1, 2} : \ d \ d {1, 2} {1, 2} : \ d {1, 2} : \ d {1, 2}) ", "product" : "[a-z] *", "price" : "[0-9] * [0-9] *"')
Str1=STR (test)
Rrs1=pattern. The.findall (str1)
Print (rrs1)
Why do I run results only get only the date and time?
[' 2019:01:01 12:12:20 ', '2019:01:02 08:05:00', '2019:02:02 09:06:05']
How to get the date, product name, the price is more than all the data?
CodePudding user response:
R '" addtimes ":" (\ d {4} : \ d {1, 2} : \ d \ d {1, 2} {1, 2} : \ d {1, 2} : \ d {1, 2}) ", "product" : "([a-z] *)", "price" : "([0-9] * [0-9] *)"')In the product and price, part of the regular also play on the brackets were captured