I want to match any string between [ and ]. Following code working fine but i want to output with out this symbol [ ]
my code:
string strValue = "{test}dfdgf[sms]";// i want to sms
private void Form1_Load(object sender, EventArgs e)
{
Match mtch = Regex.Match(strValue, @"\[((\s*?.*?)*?)\]");
if (mtch.Success)
{
MessageBox.Show(mtch.Value);
}
}
You’ll want to use Match.Groups property. Since you are already using brackets, you can get the group you want with
Groups[0] will contain the whole string with the [ and ].
Also, I think your regex can be simplified
should be equivalent to
since .* will match anything, including white space, which is what \s covers.