Npp v8.7.8 or later hangs for `^.{0,20}` at the end of a file
-
In this forum thread @coises had posted a regexp that included
{0,4000}
I wondered if the zero was needed and so tested marking with
^.{,20}
to see the first 20 characters of each line highlighted. Notepad reportedFind: Can't find the text "^.{,20}" in entire file.
That was a bit curious as I’m not sure what the engine was trying to match.I then tried
^.{1,20}
and it marks the first 20 characters for all lines that are 1 to 20 or more characters long.Next I tried
^.{0,20}
This works much like^.{1,20}
and also reports^ zero length match
on the empty lines as expected. However, when it was at the end of the file Notepad++ hangs rather than wrapping to the start of the file.^.{0,20}
works and wraps at the end of a file for npp v8.7.7.
^.{0,20}
works but hangs at the end of a file for npp v8.7.8 and v8.7.9.Before posting a bug report I’m wondering if there is something else we could try that seems useful.
-
@mkupper
Sounds like this:https://github.com/notepad-plus-plus/notepad-plus-plus/pull/16371
which was accepted but is not yet in a release.
-
@mkupper said in Npp v8.7.8 or later hangs for `^.{0,20}` at the end of a file:
Notepad reported Find: Can’t find the text “^.{,20}” in entire file. That was a bit curious as I’m not sure what the engine was trying to match.
Per Boost documentation:
Note that the “{” and “}” characters will treated as ordinary literals when used in a context that is not a repeat: this matches Perl 5.x behavior.
Leading comma within curly braces is not a valid syntax, so it’s searching for the beginning of a line followed by any one character and then the literal characters
{,20}
. -
@mkupper See also:
https://community.notepad-plus-plus.org/topic/26737/notepad-release-8-7-9/2?_=1744230923582
and following comments. -
@Coises said in Npp v8.7.8 or later hangs for `^.{0,20}` at the end of a file:
Leading comma within curly braces is not a valid syntax, so it’s searching for the beginning of a line followed by any one character and then the literal characters
{,20}
.Python’s
re
allows that syntax of omitting the minimum repetition. To use{,20}
instead of{0,20}
would be like learning a bad habit compared to Boost or other regex libraries.https://www.pcre.org/original/doc/html/pcrepattern.html quote:
An opening curly bracket that appears in a position where a quantifier is not allowed, or one that does not match the syntax of a quantifier, is taken as a literal character. For example, {,6} is not a quantifier, but a literal string of four characters.
This is stated explicitly that
{,6}
is a “literal string”.