removing #region

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.

Leave a Comment