Hi Guys, i have a concern related to regex parsing.
here is requirement, match string data through regex and convert matching data into JSON format
i have data in below string format and i need to parse matching data into json
PC : 10% Mat PC : 10% DN : 20%
PC : 10% Mat PC : 10% OP Mat : 10%
PC : 10% Mat PC : 10% PH : 10%
PC : 10% Mat PC : 10% PH : 20%
PC : 10% Mat PC : 10% PH : 20% DN : 20%
PC : 10% Mat PC : 10% PH : 30%
PC : 10% Mat PC : 10% PH : 30% DN : 20%
PC : 10% Mat PC : 10% PH : 30% OP Mat : 10%
expected output in below format
[
{
"PC":"10%",
"Mat PC":"10%",
"DN":"20%"
},
{
"PC":"10%",
"Mat":"10%",
"OP Mat":"10%"
},
{
"PC":"10%",
"Mat PC":"10%",
"PH":"20%"
},
{
"PC":"10%",
"Mat PC":"10%",
"PH":"20%"
}]
What I have tried:
i wrote below pattern to match string data
(([a-zA-Z \+\.\&\/]+)(?=:)|((?<=:)[0-9 ]+(?=%))|(?<=[0-9])%)
this pattern is working perfectly on the data matching (any optimized regex pattern will be appreciated), first part i have completed to match data through regex pattern but i don't know how to parse the same in json format through regex.