I need to remove enclosing brackets from a string in c# in code behind.
For example, if I have a string as [My [] Groups]
, I want to turn it into My [] Groups
.
Thanks.
Try this:
yourString = yourString.Replace("[", string.Empty).Replace("]", string.Empty);
Updated answer since the question was edited:
string s = "[My [] Groups]";
string pattern = @"^(\[){1}(.*?)(\]){1}$";
Console.WriteLine(Regex.Replace(s, pattern, "$2")); // will print My [] Groups