removing #region

Use one regex ^[ \t]*\#[ \t]*(region|endregion).*\n to find both: region and endregion. After replacing by empty string, the whole line with leading spaces will be removed.

[ \t]* - finds leading spaces

\#[ \t]*(region|endregion) - finds #region or #endregion (and also very rare case with spaces after #)

.*\n - finds everything after #region or #endregion (but in the same line)

EDIT: Answer changed to be compatible with old Visual Studio regex syntax. Was: ^[ \t]*\#(end)?region.*\n (question marks do not work for old syntax)

EDIT 2: Added [ \t]* after # to handle very rare case found by @Volkirith


Just use Visual Studio's built-in "Find and Replace" (or "Replace in Files", which you can open by pressing Ctrl + Shift + H).

To remove #region, you'll need to enable Regular Expression matching; in the "Replace In Files" dialog, check "Use: Regular Expressions". Then, use the following pattern: "\#region .*\n", replacing matches with "" (the empty string).

To remove #endregion, do the same, but use "\#endregion .*\n" as your pattern. Regular Expressions might be overkill for #endregion, but it wouldn't hurt (in case the previous developer ever left comments on the same line as an #endregion or something).


Note: Others have posted patterns that should work for you as well, they're slightly different than mine but you get the general idea.