Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Help: f (repeat) modifier, and histsubstpattern + :s/l/r/ modifier escaping of [{()}]



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