I have following string (CrLf
might be inserted outside {}
and ()
)
{item1}, {item2} (2), {item3} (4), {item4}
(1), {item5},{item6}(5)
I am trying to separate each item to their components and create a JSON from it using regular expression.
the output should look like this
{"name":"item1", "count":""}, {"name":"item2", "count":""}, {"name":"item3", "count":""}, {"name":"item4", "count":""}, {"name":"item5", "count":""},{"name":"item6", "count":""}
So far I have following regex
, but it does not capture second group.
\{(.[^,\n\]]*)\}\s*[\((.\d)\)]*
I am replacing the matches with
{\"name\":\"${1}\", \"count\":\"${2}\"}
Here is my test link
What I am doing wrong?
Second question
Is it possible to change items without count to zero such that my second capture group read as 0?
For example Instead of changing {item1}
to {"name":"item1", "count":""}
, it should change to {"name":"item1", "count":"0"}