Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Non-greedy matching (S-flag) behaving weird
- X-seq: zsh-users 23450
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: Non-greedy matching (S-flag) behaving weird
- Date: Fri, 8 Jun 2018 14:48:37 +0200
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=B9cN6fNRylj/5wR8DWO6iI+vO1O0+yMGe67nQuQvuTc=; b=qrC9g5WqDgQhHNuCxfxYghDcexx8W3rdomGaUc+StNABUUSSxXJDxVFgpoZcyq+nVS US/nanTINrijb0xYlucRbtONNryQhyDk5ZhhI1KTkoPJ61vAF5MVb0IPICJ74jKYduEK hVMNIfxng+/6lu01nYs71T2HVceiw0UOZRHbancpX0ANh+CJOeRwD/MgXI8gi8ElquNm GCmfx30SyOGvWS5irJhI+PbDZc4ceOEe6PBLoQ4cgwo213lcs8+fOpOGw+XRPpechxWW gJ3J4OTESUyTsaXd51tBwabtg90gvrZaYoVmAIsTh7jIeuFKDCeCZLpyl5xUp3sDZ7O4 JdDg==
- In-reply-to: <CAKc7PVA361wW_4iQL4B5wwJM1q8pdD67BJyBtxGk33q=95SDHA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CGME20180608064952epcas4p4e8890504ddaf097f8d0df1cb1e89d619@epcas4p4.samsung.com> <CAKc7PVDQcSL2fkot2i6H3YVwcp=q=bQ2DohTdfPGn2p5idH2Sw@mail.gmail.com> <20180608081535eucas1p1cf8eab9e4500aaf73521e32a19df0bf5~2IUxfX6MX1459414594eucas1p15@eucas1p1.samsung.com> <CAKc7PVA361wW_4iQL4B5wwJM1q8pdD67BJyBtxGk33q=95SDHA@mail.gmail.com>
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