C# Question

Match text outside Parentheses

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


This should work for you:

var input = "Hello, (L05-#301ME) I am a programmer.";
var output = Regex.Replace(input, @" ?\(.*?\)", string.Empty);
// output would be "Hello, I am a programmer."