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 [{()}]



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