Notepad++ with regex, re-using match variables

Here is an simple example how to use regex in notepad++ with reusing selected match variables.

For example we have special code for simulating gcm notifications. We would like to see it in pretty style.
To achieve this we must to move all elements with minus to the new lines. How to do it? Here is the solution.

We have this string:
adb shell am broadcast -a com.google.android.c2dm.intent.RECEIVE -c com.example.android.debug -n com.example.android.google.debug/com.example.android.gcm.GcmBroadcastReceiver --es "aaa" "123" --es "mmm" "bla bla bla" --es "sss" "321" --es "from" "111" --es "type" "yesterday" --es "collapse_key" "do_not_collapse"

By using bellow command in notepad++:

Searching text:

\-[a-z]{0,2}\s

Replace with:

\n($0)

We get the quite pretty result:

adb shell am broadcast
-a com.google.android.c2dm.intent.RECEIVE
-c com.example.android.debug
-n com.example.android.google.debug/com.example.android.gcm.GcmBroadcastReceiver
--es "aaa" "123"
--es "mmm" "bla bla bla"
--es "sss" "321"
--es "from" "111"
--es "type" "yesterday"
--es "collapse_key" "do_not_collapse"

Android source code from grepcode.com + Notepad++ with regex

Did You have problem with copying text from grepcode? Did You have problem with a lot spaces and wrong formatting?
Well it is possible to reformat that text with two commands using regex in notepad.

Let’s say we have this:

175

176

public void [More ...] setButtonDrawable(int resid) {

177

if (resid != 0 && resid == mButtonResource) {

178

return;

179

}

It is possible to convert original source to better format like this:

public void setButtonDrawable(int resid) {
if (resid != 0 && resid == mButtonResource) {
return;
}
mButtonResource = resid;
Drawable d = null;
if (mButtonResource != 0) {
d = getResources().getDrawable(mButtonResource);
}
setButtonDrawable(d);
}

How?

You have to paste Your selected code to Notepad++, then click CTRL+H (for replacing function). Select at the bottom option for regex. And finally make two replacing steps:
1. replace from \d+\s+\r\n to (empty text here)
1. replace from ^[\s+][\r\n$] to (empty text here)

And that’s it!