I have a regular expression (regex) question...

How would I use regular expressions to remove the contents in parenthesis in a string in C# like this:

"SOMETHING (#2)"

The part of the string I want to remove always appears within paranthesis and they are always # followed by some number. The rest of the string needs to be left alone.

Patterns:

string pattern1 = @"\(.*w*\)";
string pattern2= @"\(#\w+\)";

use Regex.Replace, as in

string newstring = rgx.Replace(oldstring, String.Empty);

@complete, have a look at this thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.