Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: input foo, output '[F|f][O|o][O|o]'?
On Mon, 1 Jul 2013, TJ Luoma wrote:
On 1 Jul 2013, at 14:44, ZyX wrote:
[...]
By the way, what regex engine is your output for? Any I am aware of
parse "[N|n]" as "either one of three characters: N, n, or pipe".
Really? I can think of several that support it. Maybe it's because I'm old
enough to remember when a lot of these utilities didn't have 'ignore case'
I think you've missed the point of "N, n, or pipe". [F|f] matches upper
'F' or lower 'f', but also the character '|'. You seem to be
conflating:
[xyz] - 'x' or 'y' or 'z'
with:
(x|y|z) - 'x' or 'y' or 'z'
The '|' doesn't mean 'or' within square brackets. It means the literal
character: '|'.
% echo "foo\nbar\nbat" | egrep -v '[F|f]'
bar
bat
% echo "foo\nb|r\nbat" | egrep -v '[F|f]'
bat
(It rejected 'b|r', because it contains '|', even though it doesn't
contain 'F' or 'f')
% echo "foo\nbar\nbat" | sed 's#[F|f][O|o][O|o]#XXX#g'
XXX
bar
bat
% echo "f|o\nbar\nbat" | sed 's#[F|f][O|o][O|o]#XXX#g'
XXX
bar
bat
(It changed 'f|o' to 'XXX', despite '|' not being 'O' or 'o')
You can also use it for matching case/esac :
case "$i" in
[C|c][R|r][A|a][S|s][H|h][P|p][L|l][A|a][N|n])
echo "matched crashplan"
;;
*)
echo "No Match"
;;
esac
(Using a smaller example:)
i='|||'
case "$i" in
[F|f][O|o][O|o]) echo matched foo ;;
*) echo no match ;;
esac
will echo:
matched foo
You really just want:
[Cc][Rr][Aa][Ss][Hh][Pp][Ll][Aa][Nn])
Messages sorted by:
Reverse Date,
Date,
Thread,
Author