I have a Json string that I need to extract some data from using Regex in C# The string is something like this:
{
"key1": "value1",
"key2": "value2",
"key3": "value3",
"key4": [
{
"arrayKey1": 1,
"arrayKey2": "something",
"arrayKey3": "somethingelse"
},
{
"arrayKey1": 2,
"arrayKey2": "something2",
"arrayKey3": "somethingelse2"
},
{
"arrayKey1": 3,
"arrayKey2": "something3",
"arrayKey3": "somethingelse3"
}
],
"some very long text here": ""
"anotherKey": "value",
"keylast": "valuelast"
}
I want to extract the array's values with named groups, I did it with the following regex: (?:"arrayKey1": (?<arrayKey1>[^"]+),[\n\t ]+"arrayKey2": "(?<arrayKey2>[^"]+)",[\n\t ]+"arrayKey3": "(?<arrayKey3>[^"]+)")
This works great and I get each match for each item of the array with 3 groups of each key.
Now I want to add an extra match that will contain only the value of "anotherKey" I can't get to work, Here are some regexs I have tried but didn't work:
(?:"arrayKey1": (?<arrayKey1>[^"]+),[\n\t ]+"arrayKey2": "(?<arrayKey2>[^"]+)",[\n\t ]+"arrayKey3": "(?<arrayKey3>[^"]+)")(?:[\s\S]*)(?:"anotherKey": "(?<anotherKey>[^"]+)")
This one does get the "anotherKey", but it only returns the first item in the array, not all of them.
Also: https://regex101.com/r/mfXlRs/1
Can someone put me in the right way?
Thanks