Useful SSMS Regular Expressions

^ is start of line marker

$ is end of line marker

\n Line Break (platform independent).  When used in the Replace expression it inserts a line break.  

 

I find SSMS regular expressions very useful.  Here's an example of what I do all of the time.  I run EXEC sp_help 'SomeTable' to get a list of columns.  I copy that list of columns into an INSERT statement.  When I copy the column list I get something that looks like this: 

ObjId
Foo
Bar
AnotherCol

And many times my column list is VERY long.  I now need to add a common after each column so I can use this in my INSERT statement.  SSMS Regular Expressions make this easier.  Here's the process:  

  1. Highlight the text
  2. Ctrl + H
  3. Tick off Use Regular Expressions
  4. Find $
  5. Replace with ,

Your output will be this:

ObjId,
Foo,
Bar
AnotherCol,

Here's how you remove the line breaks entirely:

  1. Find What:  \n
  2. Replace With:  ,

The output is:  

ObjId,Foo,Bar,AnotherCol,