Another Regexp Trick in NetBeans
By Roman Strobl on IV 10, 2005
Question: How do I replace two newlines by one in the whole file?
Answer: Not trivial :-) We've added regexp support recently into NetBeans (see my other post about back-references). You can certainly use "\\n" in the Find What field. Now you want to replace "\\n\\n" by "\\n". If you try to do this, it doesn't work, because the Replace With field converts \\n to just n (not to a newline). Too bad we can't use this kind of expressions in the Replace With field but we have to live with that for now.
But! You can use a back-reference to get the \\n into the Replace With field like this:
Using this neat trick you can replace two newlines by one. It can be used not only for newlines, but any other similar expressions starting by backslash.