Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to remove parentheses from string?

Tags:

c#

regex

I'm looking to remove the all parentheses from a given string. After some research, I've come to the conclusion that Regex was my best bet. However, looking at it (let alone looking at it, thinking about looking at it) gives me a headache. What would be the best way to approach this problem?

like image 663
Elliot Bonneville Avatar asked Jan 07 '12 07:01

Elliot Bonneville


2 Answers

The following statement removes all characters ( and ).

Regex.Replace("This (is (a) (test.", "[()]", "")   // -> "This is a test."
like image 149
Howard Avatar answered Sep 28 '22 12:09

Howard


Your question isn't very clear, or is very trivial.

Why not use String.Replace('(', '').Replace(')','')?

If you must use a regex, this is the link for how you would use a Regex.Replace

like image 27
Jeff Meatball Yang Avatar answered Sep 28 '22 12:09

Jeff Meatball Yang