Regex to extract a string between two delimeters WITHOUT also returning the delimeters?

Posted by CSharp Noob on Stack Overflow See other posts from Stack Overflow or by CSharp Noob
Published on 2010-04-30T00:49:57Z Indexed on 2010/04/30 0:57 UTC
Read the original article Hit count: 265

Filed under:

Hello,

I want to just extract the text between the brackets -- NOT the brackets, too!

My code looks currently like this:

var source = "Harley, J. Jesse Dead Game (2009) [Guard]"

// Extract role with regex

m = Regex.Match(source, @"[(.*)]"); var role = m.Groups[0].Value; // role is now "[Guard]"

role = role.Substring(1, role.Length-2); // role is now "Guard"

Can you help me to simplify this to just a single regex, instead of the regex, then the substring?

© Stack Overflow or respective owner

Related posts about c#