'How can I do a find-replace for a Backslash (\) character in zshell?

I'm trying to use a ZShell function to replace forward- and backslashes with a hyphen. So that "Hello/Every\Person" becomes "Hello-Every-Person". I can do it for the forward slash using

arg=${arg:gs/\//-}

but when I try the same syntax for the backslash it fails. Running

arg=${arg:gs/\//-}
arg=${arg:gs/\\/-}

produces "Hello-EveryPerson". It strips out the backslash, but doesn't do the replacement. I was expecting the normal rules of escaping characters to apply, so the double backslash would resolve to a character.

Can anyone tell me what I'm missing?



Solution 1:[1]

Works in zsh version 5.8 exactly as you expected.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ma-ti