I currently have a massive SQL stored procedure I need formatted. There are a lot of examples like below which I need changed:
ISNULL((SELECT SUM(ISNULL(cc.Value, 0))
-> ISNULL( ( SELECT SUM( CC.Value, 0 ) )
I need spaces added at the start and end of all brackets. Some are already in the correct format, in which case no spaces need to be added.
As well there are cases like below:
DECIMAL( 10,3 )
-> DECIMAL( 10, 3 )
Whenever there's a comma followed by a non-space character, a space should be added after the comma.
I need two Notepad++ Find and Replace regular expressions to fix the two above formatting.
For the space after a comma if not followed by a whitespace, I tried the below regex that I found, but it didn't work (it found 0 occurrences)
FIND: ,(?!$)
(or ,(?!\h*$)
)
REPLACE ,
You could try the \S
expression, which stands for "any non-whitespace character". Then if you surround it between (?=
and )
, the regex will "look ahead" to see what the next character is, without including it in the text that gets replaced.
So all together for your commas,
FIND WHAT:
,(?=\S)
REPLACE WITH:
,
Then you could do similarly with your opening parentheses. You'd have to put \(
so it knows you mean a literal opening parentheses and not trying to group something.
FIND WHAT:
\((?=\S)
REPLACE WITH:
\(
Same for your closing paren, though you'd have to use the look-behind syntax (?<=
, and you want to replace with the space beforehand:
FIND WHAT:
(?<=\S)\)
REPLACE WITH:
\)
If it's any consolation, Regex is a confusing topic even for people who've been programming their whole lives.