I'm not using text editor Notepad++ as I'm using text editor UltraEdit.
An UltraEdit macro solution for this task would be:
InsertMode
ColumnModeOff
HexOff
Top
PerlReOn
Loop 0
Find MatchCase RegExp "^[ \t]*(\w+\.text)[ \t]*=[ \t]*("[^\r\n]+)\r?\n([\s\S]+?)\.tag([ \t]*=[ \t]*)\1"
Replace All "\3\4\2"
IfNotFound
ExitLoop
EndIf
EndLoop
I explain the Perl regular expression Replace All executed on the entire file content in a loop until nothing could be replaced anymore. This Perl regular expression Replace All should work also in Notepad++.
^
... start every search at beginning of a line.
[ \t]*
... 0 or more spaces or tabs can be at beginning of a line.
\w+
... find a string with 1 or more word characters which are letters, digits and the character underscore.
\.text
... next the fixed string .text must be in the line.
The opening and closing parenthesis around \w+\.text
mark/capture the string found by this expression for backreferencing. This part of the found string is backreferenced in search string itself with \1
.
[ \t]*=[ \t]*
... next there can be 0 or more spaces or tabs before an equal sign must be found and again 0 or more spaces or tabs are found.
("[^\r\n]+)
... finds a string starting with a double quote and ending at end of the line which is also captured for backreferencing. This expression matches the text value and also a comment if present. This part of the found string is backreferenced in replace string with \2
.
\r?\n
... next a carriage return if present and a line feed is matched.
The expression up to \n
matches therefore the text definition line.
([\s\S]+?)
... a non greedy expression matching anything up to the position on which the next part of the expression returns a positive result. This expression matches everything from beginning of line below the current line with a text value definition to end of name of the matching tag value variable. For example on first run for label1.text this expression matches everything from label2.text to ledfan. This block is also captured for backreferencing in replace string with \3
.
\.tag
... the fixed string .tag
must be found next.
([ \t]*=[ \t]*)
... next there can be 0 or more spaces or tabs before an equal sign must be found and again 0 or more spaces or tabs are found. This part of the found string is captured for backreferencing with \4
in the replace string.
\1
... the name of the text value variable must be finally found, too.
I must add that this macro respectively Perl regular expression Replace All executed in a loop until nothing could be replaced anymore works only if every text value is assigned only once to a variable. If a text value like label2.text would be assigned twice to a variable, this solution would not work.
An UltraEdit macro solution working also with multiple assignments of a text value to a variable would be:
InsertMode
ColumnModeOff
HexOff
Top
UltraEditReOn
Clipboard 9
Loop 0
Find MatchCase RegExp "%[^t ]++[0-9A-Za-z_]+.text[^t ]++=[^t ]++""
IfNotFound
ExitLoop
EndIf
Key LEFT ARROW
Find MatchCase RegExp ""*$"
Copy
Key HOME
Find MatchCase RegExp "[0-9A-Za-z_]+.text"
Find MatchCase RegExp ".tag^([^t ]++=[^t ]++^)^s"
Replace All "^1^c"
DeleteLine
EndLoop
ClearClipboard
Clipboard 0
But this macro uses content of user clipboard 9 (^c
) and the currently selected text (^s
) in an UltraEdit regular expression Replace All which cannot be done with the other regular expression engines (Unix and Perl) supported by UltraEdit.
Another advantage of this solution is the deletion of lines defining a text value not assigned to any other variable in the code below. So this macro performs also a cleanup of unused text values.
I don't know how to use this method in a Notepad++ macro as I'm not using Notepad++.
The first solution working only with only 1 assignment of a text variable to another variable using a Perl regular expression Replace All could be also executed with Replace in Files command to run it on all files of a directory (tree), of course also in a loop until nothing could be replaced anymore in any file.
The UltraEdit macros for the next task requested with a comment to change
txtOssigeno.temp = GetStringResource(167)
txtFotoresistenza.temp = GetStringResource(174)
Me.txtOssigeno.Caption = Prot00026
Me.txtFotoresistenza.Caption =Prot00006
into
GetStringResource(167) = Prot00026
GetStringResource(174) = Prot00006
are with Perl regular expression engine:
InsertMode
ColumnModeOff
HexOff
Top
PerlReOn
Loop 0
Find MatchCase RegExp "^[ \t]*(\w+)\.temp[ \t]*=[ \t]*([\w()]+)[^\r\n]*?\r?\n([\s\S]+?)Me\.\1\.Caption[ \t]*=[ \t]*"
Replace All "\3\2 = "
IfNotFound
ExitLoop
EndIf
EndLoop
and with UltraEdit regular expression engine:
InsertMode
ColumnModeOff
HexOff
Top
UltraEditReOn
Clipboard 9
Loop 0
Find MatchCase RegExp "%[^t ]++[0-9A-Za-z_]+.temp[^t ]++="
IfNotFound
ExitLoop
EndIf
Find MatchCase RegExp "[0-9A-Za-z_()]+"
Copy
Key HOME
Find MatchCase RegExp "[0-9A-Za-z_]+"
Find MatchCase RegExp "Me.^s.Caption[^t ]++=[^t ]++"
Replace All "^c = "
DeleteLine
EndLoop
ClearClipboard
Clipboard 0
It is up to you which one of the 2 macros you want to use.