We help IT Professionals succeed at work.

Using REGEX to strip characters from a string

conrad2010
conrad2010 asked
on
I have a string and would like to remove everything between parentheses (including the parentheses)... which regular expression (or any other method) would accomplish this?

I'm working in VS2008, C#
Comment
Watch Question

Web Developer, specialising in WordPress
SILVER EXPERT
Most Valuable Expert 2011
Commented:
Code generated by http://www.myregextester.com
using System;
using System.Text.RegularExpressions;
namespace myapp
{
  class Class1
    {
      static void Main(string[] args)
        {
          String sourcestring = "source string to match with pattern";
          String matchpattern = @"\(.*?\)";
          String replacementpattern = @"";
          Console.WriteLine(Regex.Replace(sourcestring,matchpattern,replacementpattern));
        }
    }
}

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.