[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shouldn't /+(??) capture 2 letter files only?

From: Dan Douglas
Subject: Re: shouldn't /+(??) capture 2 letter files only?
Date: Thu, 13 Dec 2012 19:58:39 -0600
User-agent: KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; )

On Thursday, December 13, 2012 07:23:11 PM gregrwm wrote:
> i wanted to move a bunch of files & directories, all except a certain
> few, so i figured i'd use !(this|or|that).  so first i looked to see
> if +(this|or|that) isolated what i expected.  well perhaps i don't
> understand what it's supposed to do..  shouldn't /+(??) capture 2
> letter files only?
> $  echo /+(????)
> /boot /home /proc /root /sbin
> $  echo /+(???)
> /bin /dev /etc /lib /mnt /opt /run /srv /sys /tmp /usr /var
> $  echo /+(??)
> /b1 /boot /c6 /e1 /home /initrd.img /lost+found /nu /pl /pm /proc /px
> /ql /root /sbin

The +() pattern is equivalent to ()+ in ERE. It means "one or more of any 
member of the pattern list". IMO "?" is more confusing because you'd probably 
guess that it means "zero or one" as in the regex quantifier, but it's 
actually the same as ".", meaning exactly one of anything.

So, +(??) actually matches strings with even length, while +(???) matches 
those with odd length. +(?) matches any string with at least one character, 
and any number of ?'s matches multiples of that length.

 $ ksh -c 'printf %R\\n \?'
 $ ksh -c 'printf %R\\n "+(?)"'
 $ ksh -c 'printf %R\\n "+(??)"'

Dan Douglas

reply via email to

[Prev in Thread] Current Thread [Next in Thread]