How would you write a regular expression for match and replace in order to reformat C++ code from the ANSI C++ style:
if (a > 5)
{
}
to the K&R style:
if (a > 5) {
}
?
Search for \n[ \t]*\{\n
and replace with {\n
or with {\u000D\u000A
if you want to preserve the Windows-style line endings (CR+LF). Note the space in front of the brace for the replace pattern.
Explanation: match a new line followed by series of spaces and/or tabs, an open brace and another new line. Replace with a space, open brace and new line.
Worked with "Quick Replace" in Visual Studio 2010.