I built a regex to remove whitespace from qualified column names in SQL server. There could be a bunch of these in a single input string For example,
SELECT *
FROM dbo.[bad column name]
UNION
SELECT *
FROM dbo.[bad column name2]
should be
SELECT *
FROM dbo.[badcolumnname]
UNION
SELECT *
FROM dbo.[badcolumnname2]
Here is the regex search string: (\[\w*)( )([^\[\]]*?\])
Regex Replacement: $1$3
But the problem is that it needs to be called many times to replace all the whitespace in a column name.
I.e.
[bad column name]
Becomes
[badcolumn name]
Then finally the desired output
[badcolumnname]
After two successive replacement operations
What is a good way to make this regex so that it does not have to be iterative?