How can I get numbers between brackets of this text with regex in C#?
sample text :
“[1]Ali ahmadi,[2]Mohammad Razavi”
result is : 1,2
My C# code is :
string result = null;
string[] digits = Regex.Split(Text, @"[\d]");
foreach (string value in digits)
{
result += value + ",";
}
return result.Substring(0,result.Length - 1);
This will capture the numbers between brackets
(\d+), and store them in the first matched group (Groups[1]).DEMO.