Jump to content
  • Advertisement
Sign in to follow this  
athono

[.net] I have a regular expression (regex) question...

This topic is 2561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.


Share this post


Link to post
Share on other sites
Advertisement
By using this:

http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx

I have gotten some results like this:

string pattern = @"\(#\d+\)";

Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);

MatchCollection matches = rgx.Matches(interesting_string);

But I do not know what to do with the matches or what to do after this.

Share this post


Link to post
Share on other sites
It looks like using the Replace method in that same Regex class you linked to would get the job done for you. Assuming your regular expression is already matching the correct part, you could replace it with and empty string.




By using this:

http://msdn.microsof...ions.regex.aspx

I have gotten some results like this:

string pattern = @"\(#\d+\)";

Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);

MatchCollection matches = rgx.Matches(interesting_string);

But I do not know what to do with the matches or what to do after this.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!