• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Visual Studio 2010: Regex Replacement with Parenthesis

Aikouka

Lifer
I'm a pretty big fan of using regular expressions. Frankly, I just find them really fun to write; however, there's one issue that I've never been able to solve, and my Google Fu has failed me in finding a solution. The issue is that I cannot use parenthesis in the replacement field in Visual Studio 2010, and yes, I am escaping them (i.e. "\("). Whenever I do this, VS refuses to execute the replace until I replace the parenthesis, which I've either done using tagged groups (i.e. "{😛s}" and "{😛e}" in the search field and using the respective \# in the replace field) or used things like carets ('<' and '>') and replaced them later. I've also had mixed success with using the escaped parenthesis in the search field, but it usually works.

So, I'm wondering... am I missing something? I can use any other standard regex character as long as I escape it except for the (open or close) parenthesis.
 
It seems to work ok in VS 2013. If you are not using them for grouping and searching for them as text, have you tried double escaping them?
 
It seems to work ok in VS 2013. If you are not using them for grouping and searching for them as text, have you tried double escaping them?

Well, I feel like a bit of a dumb-dumb now. 😳

So, it's actually a much simpler solution... just don't escape it. I'm so used to escaping everything in the find field that I just do it in the replace field. The thing is... the only thing that you need to escape is a number as a reference to a grouping from the find field. The part that made it confusing for me is that escaping in the replace field actually works for any character except for an open/close parenthesis. So, I didn't really think anything of whether or not you actually had to do it. I sat there looking at it for a minute, and just thought, "Wait... why do I even do this? It's not like things such as grouping actually matters in the replace string." 😛
 
Back
Top