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