views:

45

answers:

3

I require a regular expression for the Visual Studio Search and Replace funtionality, as follows:

Search for the following term: sectorkey in (

There could be multiple spaces between each of the above 3 search terms, or even multiple line breaks/carriage returns.

The search term is looking for SQL statements that have hard-coded SectorKey values inside a SQL in statement. These need to be replaced with a SQL join statement - this will be done manually.

Please assist.

+2  A: 

You can use \s+ to search for one or more adjacent whitespace characters (including tab, CR, LF etc), so your regex would presumably end up looking something like sectorkey\s+in\s+\(.

Edit...

As Joe points out in his comment, it seems that Visual Studio doesn't support \s in Find/Replace expressions, in which case you'll probably need to use something like [\n:b] instead. The regex would then become sectorkey[\n:b]+in[\n:b]+\(.

LukeH
I don't think Visual Studio supports \s. See: http://msdn.microsoft.com/en-us/library/2k3te2cs(VS.80).aspx
Joe Stefanelli
+2  A: 

The little arrow to the right of the Find What box is your friend and can help you with the vagaries of the MS regex syntax.

Newline is represented by \n, so you can just do sectorkey( |\n)+in( |\n)+\( (You need to escape the open paren in your search expression, since that's used in grouping.)

dash-tom-bang
+2  A: 

I believe :Wh+ is what you want. The Visual Studio regex flavor is very strange; you'll tend to get better results if you consult the official reference. Expertise with "mainstream" regexes tends to be more of a handicap than a help when it comes to VS.

Alan Moore
Ha hah too true about the handicap.
dash-tom-bang