Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing #region

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?

like image 414
gsharp Avatar asked Feb 22 '11 20:02

gsharp


People also ask

What is mean by removing?

: 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.

What is the synonym of removing?

verbexpel from place or situation. ban. cast out. deport. discard.

What type of word is removal?

The word removal is the noun version of the verb to remove.


2 Answers

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.

like image 107
Donut Avatar answered Sep 27 '22 22:09

Donut


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

like image 32
CoperNick Avatar answered Sep 27 '22 22:09

CoperNick