Regex q: Try getting this working with grabbing the content without ( and )

  • Thread starter Thread starter natebruneau
  • Start date Start date
N

natebruneau

I want the output to look like this

Output(good):
findme

Output(bad)

(findme)

I am having trouble getting rid of ( and ). I tried adding \x28 and
\u0028 after test but same problem. Any ideas?

Thanks

-Nate
Label1.Text = "";

MatchCollection mc1 = Regex.Matches("test(findme)test", "test(?
<Content>.*?)test");

//Output match information if a match was found
if (mc1.Count > 0)
{
foreach (Match m1 in mc1)
{
Label2.Text += m1.Groups["Content"].Value;

}
 
haven't tried it, but the brackets in the regex mark the group; if you
also want literal brackets in the match, then you would probably need:
@"test\((?<Content>.*?)\)test" - i.e. the literal "test(", some other
chars, the literal ")test"

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top