Re: I think I found a bug in Lua string.patterns, can anyone help see if it's true ?
Domingo Alvarez Duarte <[email protected]> Tue, 12 May 2026 07:52:24 -0700 (PDT)
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
Thank you for all your feedback !
At the end it was my fault by expecting back slashed escaped chars to be
valid inside long strings (a painful learning today).
I've added a Lua script that dumps a pattern and looks for false escaped
chars and warn about then, it's in the same github gist
here https://gist.github.com/mingodad/4f54e0c26b66f72b21476cab6fa9fa47
On Tuesday, May 12, 2026 at 2:41:07 PM UTC+2 Spar wrote:
> That's what I said :)
> Pretend like the input box is a [[ ]] literal.
>
> YOu need to either use `"` literal for your pattern or gsub("\\n", "\n")
> On May 12, 2026 at 15:39 +0300, Domingo Alvarez Duarte <[email protected]>,
> wrote:
>
> Hello Spar ! Your tool doesn't seem to interpret '[^\n]' properly:
> ```
> [^...]Inverse set.Matches any character except:
> \Character.Doesn't match "\" literally.
> nCharacter.Doesn't match "n" literally.
> *Quantifier (zero or more).Allows to match the pattern zero or more
> times. This will match the longest sequence.
> ```
>
> On Tuesday, May 12, 2026 at 2:35:14 PM UTC+2 Domingo Alvarez Duarte wrote:
>
>> Here is the pattern after `remove_re:gsub("\n", "\\n")` that I'm now
>> looking at your tool:
>> ====
>> \n\n\nCuentas Anuales%. Ejercicio %d+
>> +Pág%. %d+\n CUENTAS ANUALES DE LA ADMINISTRACIÓN
>> GENERAL DE LA COMUNIDAD DE CASTILLA Y LEÓN%. EJERCICIO %d+\n\n\nEJECUCIÓN
>> DEL PRESUPUESTO DE GASTOS DEL EJERCICIO %d+\nGASTOS POR
>> APLICACIÓN\nADMINISTRACIÓN GENERAL[^\n]*\n[^\n]+\n\n[^\n]+\n\n
>> ====
>>
>> On Tuesday, May 12, 2026 at 2:21:24 PM UTC+2 Spar wrote:
>>
>>> Correction. It's not actually the \n. It's because you used `[[ ]]`
>>> string literals which works as C++ raw literals. They don't accept escapes.
>>>
>>> So what actually happens can be described by my tool which doesn't
>>> accept escapes too (i will fix it some day) :-)
>>>
>>> https://gitspartv.github.io/lua-patterns/?pattern=%5B%5E%5Cn%5D*
>>> On May 12, 2026 at 15:20 +0300, Luiz Henrique de Figueiredo <
>>> [email protected]>, wrote:
>>>
>>> Try this simple pattern
>>>
>>> local remove_re = "Cuentas Anuales.-CREDITO%s+"
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "lua-l" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>>
>>> To view this discussion visit
>>> https://groups.google.com/d/msgid/lua-l/CABt16qnGEsb6UYWW66PHzj6gey5g9AqWUCHpB7_zYA8P6N8Zag%40mail.gmail.com
>>> .
>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "lua-l" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
>
> To view this discussion visit
> https://groups.google.com/d/msgid/lua-l/6af79f2d-6de5-4c91-ad88-0bc68aa28d13n%40googlegroups.com
> <https://groups.google.com/d/msgid/lua-l/6af79f2d-6de5-4c91-ad88-0bc68aa28d13n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/fcd0395f-9add-4422-a8e0-a7498a844832n%40googlegroups.com.