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

Execution halted #39

Closed andry81 closed 6 months ago

andry81 commented 6 months ago

Have the file:

# dest: "d:\blabla"
#> c:\myshortcuts1\|test1.txt.lnk
e:\blabla\|test1.txt
#> c:\myshortcuts2\|test2.txt.lnk
e:\blabla\|test2.txt

Want to replace to:

# dest: "d:\blabla"
#> c:\myshortcuts1\|test1.txt.lnk
c:\myshortcuts1\|test1.txt
#> c:\myshortcuts2\|test2.txt.lnk
c:\myshortcuts2\|test2.txt

The expression:

Selected,Find,Replace,WholeWord,MatchCase,UseVariables,Regex,Extended
1,"^([^\\r\\n\\|]+)(\\|([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+))?)?)?","init({DESTDIR=""""}); if CAP1 ~= nil and string.sub(CAP1,1,2) == ""#>"" then DESTDIR=string.sub(CAP1,4,-1) elseif CAP1 ~= nil and string.len(DESTDIR) and CAP2 ~= nil then set(DESTDIR..""|""..CAP2) end",0,0,1,0,1

Result:

---------------------------
Use Variables: Execution Error
---------------------------
Execution halted due to execution failure in:

init({DESTDIR=""}); if CAP1 ~= nil and string.sub(CAP1,1,2) == "#>" then DESTDIR=string.sub(CAP1,4,-1) elseif CAP1 ~= nil and string.len(DESTDIR) and CAP2 ~= nil then set(DESTDIR.."|"..CAP2) end
---------------------------
OK   
---------------------------

Can you help with the expression?

daddel80 commented 6 months ago

Hi andry81,

There is a rule which was breached but not documented yet: set, cond, and init are not allowed to be used in if statements. I will document this. Here is the replacement string that will work with your find string:

init({DESTDIR=""}); if CAP2 ~= nil then DESTDIR = DESTDIR..CAP2 end; cond(string.sub(CAP1, 1, 1) ~= "#", DESTDIR); if CAP2 ~= nil then DESTDIR=string.sub(CAP1,4,-1) end

However, I recognized that backslashes were deleted. I will prepare a fix for this.

daddel80 commented 6 months ago

Hi andry81,

The fix for the backslash issue is ready. You can download the latest version, which includes this fix and additional enhancements, from this link Please find the files in the Artifacts frame..

This version is a pre-release and features new functionality. Notably, you can now right-click on the list to access a context menu, offering management options like Copy, Paste, and Edit.