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:
- Highlight the text
- Ctrl + H
- Tick off Use Regular Expressions
- Find $
- Replace with ,
Your output will be this:
ObjId,
Foo,
Bar
AnotherCol,
Here's how you remove the line breaks entirely:
- Find What: \n
- Replace With: ,
The output is:
ObjId,Foo,Bar,AnotherCol,
Dave Wentzel CONTENT
sql server