I had to take over a c# project. The guy who developed the software in the first place was deeply in love with #region
because he wrapped everything with regions. It makes me almost crazy and I was looking for a tool or addon to remove all #region
from the project. Is there something around?
: the act of moving away or getting rid of : the fact of being moved away or gotten rid of snow removal removal of stains. removal.
verbexpel from place or situation. ban. cast out. deport. discard.
The word removal is the noun version of the verb to remove.
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.
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: (question marks do not work for old syntax)^[ \t]*\#(end)?region.*\n
EDIT 2: Added [ \t]*
after # to handle very rare case found by @Volkirith
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With