Closed vanmorden closed 5 years ago
What version of Notepad++ and LuaScript are you using?
LuaScript v0.8 (64bit)
Notepad++ v7.7 (64-bit) Build time : May 19 2019 - 13:05:35 Path : D:\ProgramasInstalados\Notepad++\notepad++.exe Admin mode : OFF Local Conf mode : OFF OS : Windows 10 (64-bit) Plugins : CodeAlignmentNpp.dll ComparePlugin.dll DSpellCheck.dll LuaScript.dll mimeTools.dll NppConverter.dll NppFavorites.dll NppFTP.dll NppSnippets.dll SQLinFormNpp64.dll XMLTools.dll
(I modified your original post a bit to add lua syntax highlighting to the code snippets so it is easier to read)
I took this single line from your code:
regex = ("(?<=\")[A-Za-z0-9\- :\./áéíóúÁÉÍÓÚ]*(?=\";)"):format("\r\n")
And if I run this in the LuaScript console, I get:
Console:1: invalid escape sequence near '"(?<=")[A-Za-z0-9\-'
So (luckily) it means that it is something to do purely with Lua and the syntax. The root problem is that \-
is not a valid escape sequence. To fix this you either need to add a double backslash (as in \\-
) any time you need to handle this type of situation, or Lua also supports literal strings (see same reference) by surrounding the text in double brackets.
For example, both of these should be sufficient for specifying the regex you need:
regex = ([[(?<=\")[A-Za-z0-9- :./áéíóúÁÉÍÓÚ]*(?=\";)]]):format("\r\n")
regex = ("(?<=\")[A-Za-z0-9\\- :\\./áéíóúÁÉÍÓÚ]*(?=\";)"):format("\r\n")
The first line is using the double brackets, the second line adds a double backslash in front of the -
and the .
Hope this helped.
I'm afraid it doesn't work. If you use your modification, nothing is found by match command. All text in qoutes must be printed with the code of the first post. I want to find a dot (.) or hyphen (-) and you need to put a backslash before them. Whether you put two backslash the pattern change and you search for a backslash followed by any other character in the case of the dot. I think it's a problem with the way you treat the pattern before sending it to Lua.
Anyway, thanks for helping me.
Sorry. Your changes work properly, forget my last post. There was a bug in my code. The print command was incorrect. This is the correct. print("Match pos: " .. m.pos .. "Match text: " .. m.text)
The following text and code is in the current file:
Press run current file results in
If regex var is set like:
The script runs well, but nothing is found.
If use the first regex set in the Notepad++ search window it works properly and finds all quoted text.