Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Help: f (repeat) modifier, and histsubstpattern + :s/l/r/ modifier escaping of [{()}]
- X-seq: zsh-users 29149
- From: Andy Kluger <andykluger@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Help: f (repeat) modifier, and histsubstpattern + :s/l/r/ modifier escaping of [{()}]
- Date: Wed, 16 Aug 2023 14:32:51 -0400
- Archived-at: <https://zsh.org/users/29149>
- List-id: <zsh-users.zsh.org>
Hello!
For a small exercise I wanted to repeatedly remove empty pairs of
brackets/braces/parentheses from a string, and started with this
working solution:
s=$1 l=$#s
while (( 1 )) {
s=${s//(\{\}|\(\)|\[\])}
if [[ $#s < $l ]] { l=$#s } else { break }
}
print -r -- $s
But I remembered reading about the f (repeat) modifier, and thought
I'd try to remove the while loop.
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?
2. Why doesn't the replacement seem to happen to each subsequent
result of a former replacement?
Thanks for any help!
Andy
Messages sorted by:
Reverse Date,
Date,
Thread,
Author