views:

98

answers:

3

I've inherited a project where all the private variables, and there are thousands, are separated by a blank line. For instance,

    private pnlSecurityReport _pnlSecurityReport = null;

    private pnlCalendar _pnlCalendar = null;

    private CtlContacts _pnlContacts = null;

    private pnlEmails _pnlEmails = null;

    private CtlNotes _pnlNotes = null;

    private pnlRoles _pnlRoles = null;

    private pnlSecurity _pnlSecurity = null;

    private pnlSignatures _pnlSignatures = null;

This is really annoying. I'd like to remove the blank lines. Beyond writing my own tool to seek out and remove the extra line, is there a way to do this, perhaps, using RegEx-Fu in the Search and Replace dialog?

+3  A: 

Try replacing \n\n with \n, with Use Regular Expressions checked.

AakashM
This did the trick. Thx.
AngryHacker
+1  A: 

If you have UltraEdit you can to Replace | Use Regular Expressions :

Find: ^p$
Replace:"" (i.e. nothing no quotes, quotes used for illustration)

RandomNoob
+2  A: 

Not very thoroughly tested, but something like this could work: open the Replace dialog, check "Regular Expressions", enter {^:b*:w+:b+:i:b+:i:b+=:b+.*;$\n}\n into the "Find" text box, and \1 in the "Replace with" text box.

In short; match lines that matches the pattern word identifier identifier = value; followed by a blank line, tag all of the match except the last newline and then replace the full match with the tagged expression.

This will have the upside of not blindly removing all blank lines from the file, but only those that follow after typical field- or variable declarations combined with value assignments.

Expression breakdown:

{    - Start of tagged expression
^    - Match beginning of line
:b*  - Zero or more whitespace characters (such as space or tab)
:w+  - One or more alphabetic characters
:b+  - One or more whitespace characters
:i   - An identifier string
:b+  - One or more whitespace characters
:i   - An identifier string
:b+  - One or more whitespace characters
=    - an equal sign
:b+  - One or more whitespace characters
.+   - One or more characters of any kind
;    - a semicolon
$    - end of the line
\n   - a newline
}    - end of tagged expression
\n   - a newline
Fredrik Mörk