Q:

Replace each match with certain value using Notepad++ in one regular expression

I have the following code in Adobe LiveCycle Designer FormCalc:
if (form1.subform[0].complete_flag.rawValue == "1") then
    $.presence = "invisible";
endif

I want to use N++ find/replace with regular expression or similar to replace the above code to look like (to convert to JavaScript):
if (form1.subform[0].complete_flag.rawValue == "1") {
    this.presence = "invisible";
}

basically, in one run of find/replace, substitute the following:

then ==> {
$. ==> this.
endif ==> }

Is this possible using N++ or similar tools?
Tarek

A:

The regex:
(then)|(\$)|(endif)
The replace:(?1{)(?2this)(?3})
This will work in Notepad++.
A full explanation can be found here, but if that gets unlinked, the gist of it is this:

The search looks for either of three alternatives separated by the |. Each alternative has ist own capture brackets. The replace uses the conditional form ?Ntrue-expression:false-expression where N is decimal digit, the clause checks whether capture expression N matches.
-AdrianHHH

