-2

I have a string

string s = Hello, (L05-#301ME) I am a programmer.

I need to extract this to

string result = Hello, I am a programmer

That mean I need to get all text ouside the parentheses. How can I use RegEx to do this task

Tung Kieu
  • 79
  • 9
  • Look at the answers here: http://stackoverflow.com/questions/1388207/how-to-remove-text-in-brackets-using-a-regular-expression http://stackoverflow.com/questions/1359412/c-sharp-remove-text-in-between-delimiters-in-a-string-regex – sachin Oct 03 '16 at 06:34
  • You could replace all pairs of parentheses (along with the content in between) with an empty string. – Steve Oct 03 '16 at 06:35

1 Answers1

4

This should work for you:

var input = "Hello, (L05-#301ME) I am a programmer.";
var output = Regex.Replace(input, @" ?\(.*?\)", string.Empty);
Console.WriteLine(output);
// output would be "Hello, I am a programmer."
sachin
  • 2,341
  • 12
  • 24