I have json string and i am trying to find value of key formId using regex. In json i have two formids. Regex is returning me two groups but second group is duplicate of first group.
My c# code is:
string json = System.IO.File.ReadAllText("data.json");
string regex = "(?<=\"formId\": \")(.*)(?=\")";
Match match = Regex.Match(json.ToLower(), regex,RegexOptions.IgnoreCase);
foreach (var item in match.Groups)
{
Console.WriteLine(item.ToString());
}
Console.ReadLine();
Json string is
{
"StepState": {
"id": "f0f0e0c8-b4c7-45ff-b72d-58191d43a01f",
"steps": [
{
"stepContent": {
"context": {
"formId": "af677fcd-4a34-42ed-acc1-91ded7734167",
}
}
},
{
"stepContent": {
"context": {
"formId": "3f6242a5-ff80-4f35-8589-d81bb545700e",
}
}
}
]
}
}
What am i missing? Is there any issue in regex?