Regex for end-of-file anchor



  • Not sure if this is a bug in the regex engine, or an inaccuracy of the online user manual, or just me misunderstanding something as usual…

    The manual states that \z or \` matches the end of the matching string, which I believe also means they can match the end of the file. \z works perfectly for me for that purpose, but \` seems to not match anything for me. Comments/corrections/criticisms? (I don’t have to, nor have any burning desire to, use \` , but just pointing this seeming discrepancy out, since it’s in the manual.)



  • There is indeed an issue, \' matches the end buffer and the other the start of buffer

    14a93da9-d909-4601-a063-084b6710bd54-image.png

    0fb69a35-aff1-426b-a314-bc9ea4db462e-image.png



  • @PeterJones - issue and pr opened.
    @M-Andre-Z-Eckenrode - thank you for reporting the issue.



  • Hello, @m-andre-z-eckenrode, @ekopalypse, @peterjones and All ,

    The manual states :

    • \A or \' => The start of the matching string.

    • \z or \` => The end of the matching string.

    • \Z Matches like \z with an optional sequence of newlines before it. This is equivalent to (?=\v*\z), which departs from the traditional Perl meaning for this escape.

    Well, there is some typos here !

    Indeed, the correct text should be :

    • \A or \` or (?-m)^ => The start of the matching string.

    • \z or \' or (?-m)$ => The end of the matching string.

    • \Z Matches like \z with an optional sequence of vertical blank characters before it. This is equivalent to the assertion
      (?=[\n\f\r\x85\x{2028}\x{2029}]*\z), which departs from the traditional Perl meaning for this escape.

    So, @ekopalypse, there is absolutely no regex issue at all !!


    Notes :

    • For a correct behavior of the \A assertion, whatever its syntax, you must use, at least, Notepad++ v7.9.1

    • The \Z assertion is not stricly equivalent to (?=\v*\z) as the \v character class is identical to the [\n\x0B\f\r\x85\x{2028}\x{2029}] character class

    Best Regards,

    guy038



  • @guy038

    ?? - but you yourself state that the documentation is wrong ??
    What am I missing??



  • Hi, @m-andre-z-eckenrode, @ekopalypse, @peterjones and All,

    Sorry, @ekopalypse. I misspoke :

    Of course, an issue should be created to modify this part of the N++ official documentation !

    But, from a functional and regex point of view, the assertions \` , \' work properly and are identical, respectively, to the \A and \z assertions !

    BR

    guy038



  • @guy038 - ok and I’ve created the issue and the pull request already. Just needs to be merged.



  • @guy038 said in Regex for end-of-file anchor:

    The manual states :

    \A or ’ => The start of the matching string.

    \z or ` => The end of the matching string.

    If the manual is being improved, how about really improving it?

    “The start of the matching string” and “The end of the matching string” are not very good phrases for the Notepad++ user/manual.

    I guess they work fine in the context of a programmer calling the Boost C++ function (where these phrases originated from, I think).

    But why aren’t they referred to in the Notepad++ user manual as relating to start-of-file and end-of-file, respectively?



  • @Alan-Kilborn said in Regex for end-of-file anchor:

    But why aren’t they referred to in the Notepad++ user manual as relating to start-of-file and end-of-file, respectively?

    Makes sense to me. @Ekopalypse , when you get a chance, could you update your PR?



  • @Ekopalypse ,

    Thanks for PR#197. It has been merged, and will be in the next release.

    @M-Andre-Z-Eckenrode ,

    For now, you can see the updated docs in searching.md. The fixes will be in the live document the next time there’s a website release (probably after NPP v7.9.6 is released).



  • @PeterJones and everyone else —

    Looks good, thanks!


Log in to reply