Comments (17)
Hi andry81,
please test the following Build:
Besides, your previous regex ^(.+)\\
was only reading the string up to the last \
. The previous error occurred because it didn’t stop at the last \
but at the last dot, which is now fixed.
You can also test it with the string:
#> c:\test1\test1.aaa|test1.txt.lnk
and this expresion:
1,"^(.+)$","set(string.match(CAP1, ""^(.+)\\\\""))",0,0,1,0,1
which should be that resukt:
#> c:\test1\
from notepadpp-multireplace.
Hi andry81,
The following build will support nil in the cond statement as long as it is not passed as a replacement string, so your REPLACETO with nil expression will work. However, as I previously said, it will not produce any different output compared to REPLACETO with an empty string "". Build 409
from notepadpp-multireplace.
Maybe you didn't confirm the Administrator privileges when copying the DLL into the Plugin directory.
I've used Total Commander and might be there were a different dialog with the Skip
button (because of locked DLL) instead of Overwrite
button.
from notepadpp-multireplace.
i tested it with latest build and it works for me.
False alarm, CAP1 already is a half of string without |
:)
from notepadpp-multireplace.
Hi andry81,
i found the issue. You have to chaneg the assignemnet of DESTDIR into that:
DESTDIR = string.match(string.sub(CAP1, 4, -1), "^(.+[^\\])\\?")
Fixed complete Replace statement should look like this:
init({DESTDIR="", REPLACETO=""});if CAP1 ~= nil and string.sub(CAP1, 1, 3) == "#> " then DESTDIR = string.match(string.sub(CAP1, 4, -1), "^(.+[^\\])\\?");elseif CAP1 ~= nil and string.sub(CAP1, 1, 1) ~= "#" and string.len(DESTDIR) > 0 and CAP2 ~= nil then REPLACETO = DESTDIR .. "\\|" .. CAP2;end;cond( CAP1 ~= nil and CAP2 ~= nil and string.len(CAP1) > 0 and string.len(CAP2) > 0 and string.sub(CAP1, 1, 1) ~= "#" and string.len(REPLACETO) > 0, REPLACETO);
The plugin is supporting these special signs in regex since latest version:
{'\\', '^', '$', '.', '|', '?', '*', '+', '(', ')', '[', ']', '{', '}' }
Please check this and let me know!
As these Lua expressions can sometimes become unreadable if they are too complex, it is often better to structure them before copying into Replace. To facilitate this, I have enhanced the Edit Field in the list. It now deletes all line feeds (LF) before copying the text into the Find and Replace field of the list. You can open these Edit fields via the context menu, which you can access by right-clicking on a list entry. However, you need to be aware of the semicolons and spaces before copying. Try this.
init({DESTDIR="", REPLACETO=""});
if CAP1 ~= nil and string.sub(CAP1, 1, 3) == "#> " then
DESTDIR = string.match(string.sub(CAP1, 4, -1), "^(.+[^\\])\\?");
elseif CAP1 ~= nil and string.sub(CAP1, 1, 1) ~= "#" and string.len(DESTDIR) > 0 and CAP2 ~= nil then
REPLACETO = DESTDIR .. "\\|" .. CAP2;
end;
cond(
CAP1 ~= nil and CAP2 ~= nil and
string.len(CAP1) > 0 and string.len(CAP2) > 0 and
string.sub(CAP1, 1, 1) ~= "#" and string.len(REPLACETO) > 0,
REPLACETO
);
It is not released yet but you can download this feature with that build:
I hope you find it usefull
from notepadpp-multireplace.
"^(.+)\\"
This is legit expression, why it stops by the dot?
By the way I've tested yours expression (^(.+[^\\])\\?
) and it is somehow not compatible with the standard implementation: https://regex101.com/
Yes, I know it works in your case, but it must match the whole line.
from notepadpp-multireplace.
I've tested mine and yours expressions and it works as expected in the online Lua regexp tester:
https://www.mycompiler.io/view/JbGtKVnln5X
https://www.mycompiler.io/view/GQ5wqROnsES
from notepadpp-multireplace.
Hi andry81,
It seems I always need a second look ;-) But now I see the error with the dot. The issue is that Lua pattern matching escapes special characters with the % sign, except for the backslash. This conflicts with the regular expressions masking in Notepad++. I will go ahead and fix this.
Thank you for your patience.
Additionally, you can use this statement without any pattern matching since you are reading the complete line into CAP1. You can also verify this by adding set(CAP1).
init({DESTDIR="", REPLACETO=""});
if CAP1 ~= nil and string.sub(CAP1, 1, 3) == "#> " then
DESTDIR = string.sub(CAP1, 4, -1);
elseif CAP1 ~= nil and string.sub(CAP1, 1, 1) ~= "#" and string.len(DESTDIR) > 0 and CAP2 ~= nil then
REPLACETO = DESTDIR .. "\\|" .. CAP2;
end;
cond(
CAP1 ~= nil and CAP2 ~= nil and
string.len(CAP1) > 0 and string.len(CAP2) > 0 and
string.sub(CAP1, 1, 1) ~= "#" and string.len(REPLACETO) > 0,
REPLACETO
);
I will keep you informed when the next build is ready...
from notepadpp-multireplace.
Hi andry81,
The last \
should be deleted in this example. The previous Build was not accurate.
#> c:\test1
of the text
#> c:\test1\test1.aaa|test1.txt.lnk
with that expression:
1,"^(.+)$","set(string.match(CAP1, ""^(.+)\\\\""))",0,0,1,0,1
this is updated in that build:
Build 407
from notepadpp-multireplace.
Seems it still match the dot.
I've a bit improved the code:
1,"^([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+))?)?)?","init({DESTDIR="""",REPLACETO=""""}); if CAP1 ~= nil and string.sub(CAP1,1,3) == ""#> "" then DESTDIR=string.match(string.sub(CAP1,4,-1),""^(.+)\\\\"") elseif CAP1 ~= nil and string.sub(CAP1,1,1) ~= ""#"" and DESTDIR ~= nil and string.len(DESTDIR) > 0 and CAP2 ~= nil then REPLACETO=DESTDIR..""\\\\|""..CAP2 else REPLACETO=nil end; cond(CAP1 ~= nil and CAP2 ~= nil and string.len(CAP1) > 0 and string.len(CAP2) > 0 and string.sub(CAP1,1,1) ~= ""#"" and REPLACETO ~= nil and string.len(REPLACETO) > 0, REPLACETO)",0,0,1,0,1
As I understand the REPLACETO
variable still must be resetted in case of no match to avoid accidental replacement. But it reports the error:
---------------------------
Use Variables: Syntax Error
---------------------------
[string "function cond(cond, trueVal, falseVal)..."]:8: trueVal cannot be nil
---------------------------
OK
---------------------------
If replace REPLACETO=nil
by REPLACETO=""
, then it still has incorrect dot match:
1,"^([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+))?)?)?","init({DESTDIR="""",REPLACETO=""""}); if CAP1 ~= nil and string.sub(CAP1,1,3) == ""#> "" then DESTDIR=string.match(string.sub(CAP1,4,-1),""^(.+)\\\\"") elseif CAP1 ~= nil and string.sub(CAP1,1,1) ~= ""#"" and DESTDIR ~= nil and string.len(DESTDIR) > 0 and CAP2 ~= nil then REPLACETO=DESTDIR..""\\\\|""..CAP2 else REPLACETO="""" end; cond(CAP1 ~= nil and CAP2 ~= nil and string.len(CAP1) > 0 and string.len(CAP2) > 0 and string.sub(CAP1,1,1) ~= ""#"" and REPLACETO ~= nil and string.len(REPLACETO) > 0, REPLACETO)",0,0,1,0,1
Result:
# dest: "d:\blabla"
#> c:\test1\test1.aaa\|test1.txt.lnk
c:\test1\test1.aaa\|test1.txt
#> c:\test2\test2.bbb|test2.txt.lnk
c:\test2\test2|test2.txt
The last line is replaced to c:\test2\test2|test2.txt
instead of c:\test2|test2.txt
.
from notepadpp-multireplace.
Hi andry81,
I haven't delved deeply into your logic, but if you are looking to achieve this result:
# dest: "d:\blabla"
#> c:\test1\test1.aaa|test1.txt.lnk
c:\test1\test1.aaa|test1.txt
#> c:\test2\test2.bbb|test2.txt.lnk
c:\test2\test2.bbb|test2.txt
You can do it with the following statement:
init({DESTDIR="", REPLACETO=""});
if CAP1 ~= nil and string.sub(CAP1, 1, 3) == "#> " then
DESTDIR = string.sub(CAP1, 4, -1);
elseif CAP1 ~= nil and string.sub(CAP1, 1, 1) ~= "#" and string.len(DESTDIR) > 0 and CAP2 ~= nil then
REPLACETO = DESTDIR .. "|" .. CAP2;
end;
cond(
CAP1 ~= nil and CAP2 ~= nil and
string.len(CAP1) > 0 and string.len(CAP2) > 0 and
string.sub(CAP1, 1, 1) ~= "#" and string.len(REPLACETO) > 0,
REPLACETO
);
Is this the result you are looking to achieve?
from notepadpp-multireplace.
Is this the result you are looking to achieve?
init({DESTDIR="",REPLACETO=""});
if CAP1 ~= nil and string.sub(CAP1,1,3) == "#> " then
DESTDIR=string.match(string.sub(CAP1,4,-1),"^(.+)\\")
elseif CAP1 ~= nil and string.sub(CAP1,1,1) ~= "#" and DESTDIR ~= nil and string.len(DESTDIR) > 0 and CAP2 ~= nil then
REPLACETO=DESTDIR.."\\|"..CAP2
else
REPLACETO=nil
end;
cond(
CAP1 ~= nil and CAP2 ~= nil and
string.len(CAP1) > 0 and string.len(CAP2) > 0 and
string.sub(CAP1,1,1) ~= "#" and REPLACETO ~= nil and string.len(REPLACETO) > 0,
REPLACETO
)
I've used REPLACETO=nil
, which is valid Lua expression as said here: https://www.lua.org/pil/2.1.html
you can assign nil to a global variable to delete it
But instead it raises an error.
If replace to REPLACETO=""
it does not work as expected, when the ^(.+)\\
is a valid expression but instead it matches a string with the dot as the last character while must not.
from notepadpp-multireplace.
Hi andry81,
Actually, any value passed to the true or false value part in cond
cannot be nil, even if the condition doesn't pass it through. In fact, it doesn't matter whether the condition passes the set value for true or not.
However, it is a good point to avoid unnecessary error messages. I will fine-tune the cond
statement so that an error will only occur for nil values if the condition tries to push a nil as a replace string.
If you are using "" for REPLACETO your result looks like that:
# dest: "d:\blabla"
#> c:\test1\test1.aaa|test1.txt.lnk
c:\test1\|test1.txt
#> c:\test2\test2.bbb|test2.txt.lnk
c:\test2\|test2.txt
This is statement with REPLACETO set to "":
1,"^([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+)(?:\\|([^\\r\\n\\|]+))?)?)?","init({DESTDIR="""", REPLACETO=""""}); if CAP1 ~= nil and string.sub(CAP1, 1, 3) == ""#> "" then DESTDIR = string.match(string.sub(CAP1, 4, -1), ""^(.+)\\\\"");elseif CAP1 ~= nil and string.sub(CAP1, 1, 1) ~= ""#"" and DESTDIR ~= nil and string.len(DESTDIR) > 0 and CAP2 ~= nil then REPLACETO = DESTDIR .. ""\\\\|"" .. CAP2; else REPLACETO = ""d""; end; cond( CAP1 ~= nil and CAP2 ~= nil and string.len(CAP1) > 0 and string.len(CAP2) > 0 and string.sub(CAP1, 1, 1) ~= ""#"" and REPLACETO ~= ""d"" and string.len(REPLACETO) > 0, REPLACETO);",0,0,1,0,1
The filenames like test1.aaa
and test2.bbb
are ignored because you are filtering them with the last \
using this statement: "^(.+)\"
I will post a new build with an updated cond
soon, but setting REPLACETO to nil or "" will not change the result. However, it will avoid error messages for nil set as the true value.
from notepadpp-multireplace.
This is statement with REPLACETO set to "":
I swear I've copied your last 407 build DLL, but it somehow restored back. Can Notepad++ restore DLL overwrite back while working?
from notepadpp-multireplace.
Hi andry81,
No, Notepad++ itself does not typically revert or restore DLL files back to a previous state on its own after they have been replaced or updated. Maybe you didn't confirm the Administrator privileges when copying the DLL into the Plugin directory.
from notepadpp-multireplace.
Build 409
The expression ^(.+)\\?
stops by |
character when should not: https://www.mycompiler.io/view/7BM1NgD5hI3
I know it is not related to this issue, but still another issue.
from notepadpp-multireplace.
Hi andry81,
i tested it with latest build and it works for me.
Input String will not be changed
"#> c:\test1\test1.aaa|test1.txt.lnk
with that statememt:
1,"^(.+)$","set(string.match(CAP1, ""^(.+)\\\\?""))",0,0,1,0,1
but for confirmation this is deleting till |
sign:
1,"^(.+)$","set(string.match(CAP1, ""^(.+)|""))",0,0,1,0,1
Please double-check if you are really using build 409. It looks for me like the fixed error. It's always better to delete old DLLs before copying and overwriting them.
from notepadpp-multireplace.
Related Issues (20)
- Additional MSBuild files not in .gitignore
- Vcxproj file errors and cleanup
- Wrong dlgID in multiReplace()
- Escape key to close dialog HOT 2
- 32-bit build failing due to sign mismatch warning and treat warnings as errors HOT 1
- The vs.proj/Win32 directory needs to be added to .gitignore
- Version is misreported HOT 1
- Make Escape key close smarter
- 32-bit build warning as error signed mismatch (again)
- 32-bit warning as error again
- "export to Bash" HOT 2
- all open documents HOT 2
- Regexp rename with a counter HOT 6
- The newer versions can't not run on NPP v8.5.7 x64 HOT 2
- Ability to translate the plugin HOT 8
- Replace using Capture Variables HOT 1
- Replace All and Selection HOT 2
- Execution halted HOT 2
- Parentheses incorrect replacement in regexp expression HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from notepadpp-multireplace.