From: Bart Schaefer <schaefer@brasslantern.com>
To: Andy Kluger <andykluger@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Help: f (repeat) modifier, and histsubstpattern + :s/l/r/ modifier escaping of [{()}]
Date: Wed, 16 Aug 2023 20:19:37 -0700 [thread overview]
Message-ID: <CAH+w=7Y+zos=sRfAv2769iJEzazHRfT4u6v+3B3mGoxy8Yv0-w@mail.gmail.com> (raw)
In-Reply-To: <CAO4D9E=+O-=66w0um7OzENVEiV11QfVUWYSTocacUX4rhYr1=Q@mail.gmail.com>
On Wed, Aug 16, 2023 at 11:33 AM Andy Kluger <andykluger@gmail.com> 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.
next prev parent reply other threads:[~2023-08-17 3:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 18:32 Andy Kluger
2023-08-17 3:19 ` Bart Schaefer [this message]
2023-08-17 23:09 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7Y+zos=sRfAv2769iJEzazHRfT4u6v+3B3mGoxy8Yv0-w@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=andykluger@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).