From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13593 invoked by alias); 2 Jul 2013 02:01:22 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17849 Received: (qmail 14468 invoked from network); 2 Jul 2013 02:01:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at benizi.com designates 64.130.10.15 as permitted sender) Date: Mon, 1 Jul 2013 21:53:01 -0400 (EDT) From: "Benjamin R. Haskell" To: TJ Luoma cc: ZyX , Zsh-Users List Subject: Re: input foo, output '[F|f][O|o][O|o]'? In-Reply-To: Message-ID: References: <694051372704284@web26e.yandex.ru> User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII 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])