How to include second square brackets in my match result. If I have regex like
\[msg.(?<msgfield>.*?)\]
My input string is
[url]/XYZ/[SomeClass.Entity["Id"]]
Then how to get the result match of Entity["Id"]
.
Here is what I tried so far. I am missing the last ]
. The result of my code is Entity["Id"
.
Also, the input string could be [url]/XYZ/[SomeClass.EntityId]
. It should give result of EntityId
then.
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
String sample = "[url]/XYZ/[SomeClass.Entity[\"Id\"]]";
Regex regex = new Regex(@"\[SomeClass.(?<msgfield>.*?)\]");
Match match = regex.Match(sample);
if (match.Success)
{
Console.WriteLine(match.Groups["msgfield"].Value);
}
}
}