Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Non-greedy matching (S-flag) behaving weird



Turns out I was just confused. Vim does 2 adjacent matches, that's why
it looked like till-END would happen. Adding /e switch to the
search-regex showed that first match ends at BEGIN.

So those are 2 examples showing how non-greedy should behave.


On 8 June 2018 at 14:42, Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> On 8 June 2018 at 10:15, Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
>> You've got a "*" at the beginning and the end  They're both doing
>> matching --- they're is no single "matching" to which a rule applies ,
>> there are just separate patterns all attempting to match.  You're going
>> to have to work out some way of forcing one of them to match more than
>> the other.
>
> You are apparently right, but it is a big surprise to me. * matching
> over what (a|b) should match, on string xxxaxxxb?? Well, this test
> works like I would expect:
>
> ~ buf='xxxaxxxbxxx'; print "${(S)buf/(#b)(*)(a|b)(*)/R}"
> Rxxxbxxx
>
> With greedy search (no (S)-flag):
>
> ~ buf='xxxaxxxbxxx'; print "${buf/(#b)(*)(a|b)(*)/R}"
> R
>
> However, I also tested vim, entering text:
>
> abcd BEGIN efgh END ijkl
>
> And then running matching with regex: .\{-}\(BEGIN\|END\).\{-}
>
> \{-} is non-greedy match. YET, this matched till END, not till BEGIN.
> Very weird.
>
> --
> Best regards,
> Sebastian Gniazdowski



Messages sorted by: Reverse Date, Date, Thread, Author