zsh-users
 help / color / mirror / code / Atom feed
From: "Benjamin R. Haskell" <zsh@benizi.com>
To: TJ Luoma <luomat@gmail.com>
Cc: ZyX <kp-pav@yandex.ru>, Zsh-Users List <zsh-users@zsh.org>
Subject: Re: input foo, output '[F|f][O|o][O|o]'?
Date: Mon, 1 Jul 2013 21:53:01 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LNX.2.01.1307012129050.21264@hp.internal> (raw)
In-Reply-To: <E7CF18D5-CB4B-4E80-B7E0-40D5930E42DD@gmail.com>

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])


  parent reply	other threads:[~2013-07-02  2:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-01 17:59 TJ Luoma
2013-07-01 18:44 ` ZyX
2013-07-02  0:58   ` TJ Luoma
2013-07-02  1:30     ` Lawrence Velázquez
2013-07-02  1:53     ` Benjamin R. Haskell [this message]
2013-07-02  4:24       ` TJ Luoma
2013-07-02  3:51     ` ZyX
2013-07-02  4:00       ` ZyX
2013-07-02 23:24         ` Phil Pennock
2013-07-01 19:37 ` Phil Pennock
2013-07-02  0:24   ` TJ Luoma
2013-07-01 23:51 ` Alex Satrapa
2013-07-02  0:38   ` Kurtis Rader
2013-07-02  1:11     ` TJ Luoma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.01.1307012129050.21264@hp.internal \
    --to=zsh@benizi.com \
    --cc=kp-pav@yandex.ru \
    --cc=luomat@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).