Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: input foo, output '[F|f][O|o][O|o]'?
On Jul 1, 2013, at 8:58 PM, TJ Luoma <luomat@xxxxxxxxx> 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'
>
> % echo "foo\nbar\nbat" | egrep -v '[F|f]'
> bar
> bat
>
> % echo "foo\nbar\nbat" | sed 's#[F|f][O|o][O|o]#XXX#g'
> XXX
> bar
> bat
These regex are not matching what you think they are matching. For sure, "[F|f]" matches both lowercase and uppercase F, but as ZyX said, it also matches pipe characters:
% echo "foo\nbar\nbaz\nbar|||baz" | egrep -v '[F|f]'
bar
baz
% echo "foo\nbar\nbaz\nbar|||baz" | sed 's/[F|f][O|o][O|o]/XXX/g'
XXX
bar
baz
barXXXbaz
You are probably thinking of "(F|f)"; you should just use "[Ff]".
> 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
Same misconception here; pipes in patterns' bracket expressions have no special meaning. You can remove all the pipes from your example, and it would still work.
% case "crasHPLan" in
case> [Cc][Rr][Aa][Ss][Hh][Pp][Ll][Aa][Nn]) echo "matched";;
case> *) echo "did not match";;
case> esac
matched
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author