Regular Expression Visual Studio 2013

I have a project in Visual Studio 2013 and I am facing issues with 3-part naming.
I found out that a workaround is to replace [DB] of [DB].[Schema].[Table] from global variable [$(DatabaseName)]. But the problem is there are some statements which are like:

@cmd "SELECT * FROM [DB].[Schema].[Table]"

and there are comments too both single line comments and multi-line comments

I have lines like these:

  • SELECT @cmd = ‘ INSERT PhoenixCommon.dbo.ObjectAdministration’ +
  • , @cmdFrom = ‘ FROM PhoenixCommon.dbo.ObjectAdministration oad’ +
  • ** 02/08/08 Ed White Updated for PhoenixCommon DB
  • — FROM PhoenixCommon.dbo.UserAccount

In these lines I don’t want to change “PheonixCommon” with “[$(DatabaseName)]”

but lines like this:

  • JOIN PhoenixCommon.dbo.Object obj WITH (NOLOCK)
  • UPDATE PhoenixCommon.dbo.Organization
  • FROM PhoenixCommon.dbo.Organization

In these type of lines I want to replace PheonixCommon with [$(DatabaseName)]

Any suggestion how can I replace those [DB] (in this casePheonixCommon) from [$(DatabaseName)] using regular expression. Any other ideas are most welcome.

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.