Here’s the problem: Sometimes I document an SP in MS Word, then copy-paste the paragraph into a comment block in the SP. Of course, when I do this, the paragraph is in one big long string:
It’s a little thing, but I really want to be able to READ the comments. What I want, then, is to go about 40 characters, find a space, and start a newline. But not by hand.
That’s the pseudocode for the RegEx solution, as it turns out.
The breakdown of “Find what”, {.^40} :
- “.^40” says “find any 40 characters”.
- The curly braces “tag” the expression found – we can then reference those found characters later.
- The space after the closing curly brace (which you can’t really see) says “I want to find 40 characters, but they MUST BE FOLLOWED by a space”. If I didn’t add the space, we’d insert newlines in the middle of words, instead of at the end.
The breakdown of “Replace with”, \1 \n:
- “\1” references that found expression, the 40 characters discovered in the curly braces above. I want to keep those, so I start my “replace with” with the actual characters found.
- “\n” is a newline.
The result:
SO SUPER AWESOME.
- Official reference for you: Regular Expressions (Visual Studio)
- Sean’s RegEx for DBAs class
- The code download for that same class
Happy days,
Jen McCown
http://www.MidnightDBA.com/Jen
Have you checked out Minion Reindex yet? It’s our free, easy, comprehensive index maintenance solution. You’ll love it, seriously.
Pingback: SSMS regular expressions: format text into a block - SQL Server - SQL Server - Toad World
Pingback: Dew Drop – April 8, 2015 (#1989) | Morning Dew
Pingback: SSMS: Query Shortcuts and Other Tips – The Brewing DBA