Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Help: f (repeat) modifier, and histsubstpattern + :s/l/r/ modifier escaping of [{()}]
- X-seq: zsh-users 29150
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Andy Kluger <andykluger@xxxxxxxxx>
- Cc: zsh-users@xxxxxxx
- Subject: Re: Help: f (repeat) modifier, and histsubstpattern + :s/l/r/ modifier escaping of [{()}]
- Date: Wed, 16 Aug 2023 20:19:37 -0700
- Archived-at: <https://zsh.org/users/29150>
- In-reply-to: <CAO4D9E=+O-=66w0um7OzENVEiV11QfVUWYSTocacUX4rhYr1=Q@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAO4D9E=+O-=66w0um7OzENVEiV11QfVUWYSTocacUX4rhYr1=Q@mail.gmail.com>
On Wed, Aug 16, 2023 at 11:33 AM Andy Kluger <andykluger@xxxxxxxxx> wrote:
>
> setopt histsubstpattern
> s='left[()]over'
> print -rl -- ${s:fs/(\\{\\}|\\(\\)|\\[\\])//}
> # printed: left[]over
> # expected: leftover
>
> I'm having two confusions:
>
> 1. Why do I need to double-backslash before each
> brace/bracket/parenthesis, rather than single-backslash?
Because the pattern is being passed through possible parameter
substitution before being passed through the pattern parser.
> 2. Why doesn't the replacement seem to happen to each subsequent
> result of a former replacement?
Because there's a bug. The pattern (and the replacement, though it's
empty in this case) are both rewritten in-place by at least one of
those two substitution passes, so the pattern isn't the same the
second time around and no longer matches.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author