daddel80 / notepadpp-multireplace

MultiReplace is a plugin for Notepad++ enabling multi-string replacement, allowing list saving and loading. It provides CSV syntax highlighting and enabling precise column targeting. Additionally, it introduces conditional and computational operations within the replacement string.
GNU General Public License v2.0
20 stars 7 forks source link

Replace using Capture Variables #35

Closed andry81 closed 9 months ago

andry81 commented 9 months ago

Trying to renumber the ini keys from https://github.com/daddel80/notepadpp-multireplace/issues/31 with new syntax:

Find what:

^(button|cmd|param|path|iconic|menu)\d*=

Replace with:

init({BTTNCNT=0}); if "$1" == "button" then BTTNCNT=BTTNCNT+1 end; set("$1"..BTTNCNT.."=")

But it does not seem to work.

The set always returns .0=.

daddel80 commented 9 months ago

Hi andry81,

You were pretty close to the result. Just replace $1 with CAP1. The issue here is that $1 will not be resolved in the "Use Variables" environment. Therefore, it cannot be used in conditions or calculations. $1 can be passed through set and cond functions, and it is Notepad++ that finally resolves it. However, this can also cause trouble if you concatenate $1 with a trailing number. So, always use CAP1 instead of $1.

Besides that, there is also a CNT variable. But your solution is better for your purposes!

Here is the correction:

Find what:

^(button|cmd|param|path|iconic|menu)\d*=

Replace with:

init({BTTNCNT=0}); if CAP1 == "button" then BTTNCNT=BTTNCNT+1 end; set(CAP1..string.format("%.0f", BTTNCNT).."=")

I will go to make the difference more clear in the README between $x and CAPx Variables.