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

General software, Operating Systems, and Programming discussion.
Everything from software questions, OSes, simple HTML to scripting languages, Perl, PHP, Python, MySQL, VB, C++ etc.
Post Reply
User avatar
complete
Member
Posts: 75
Joined: Fri Aug 26, 2005 11:08 am

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

Post by complete »

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.
Stu
Regular Member
Posts: 341
Joined: Tue Aug 10, 1999 12:00 am

Post by Stu »

I'm not sure about the C# part (I would imagine it would be done using Regex.Replace based on a quick googling), but one regex that would do the trick is this:

Code: Select all

\(#[^)]+\)
chriselviss
New Member
Posts: 1
Joined: Thu Jul 26, 2012 1:16 pm

Post by chriselviss »

complete wrote: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.
You can delete the subkey like

rKey = Registry.LocalMachine.OpenSubKey("Software", true);
rKey.DeleteSubKey("AppReg", true);

if you not clear look:

http://net-informations.com/csprj/overv ... ations.htm

chris.
Post Reply