From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14691 invoked from network); 18 Feb 2005 00:16:01 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 18 Feb 2005 00:16:01 -0000 Received: (qmail 28668 invoked from network); 18 Feb 2005 00:15:56 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 18 Feb 2005 00:15:56 -0000 Received: (qmail 29295 invoked by alias); 18 Feb 2005 00:15:38 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8521 Received: (qmail 29274 invoked from network); 18 Feb 2005 00:15:37 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 18 Feb 2005 00:15:37 -0000 Received: (qmail 27326 invoked from network); 18 Feb 2005 00:15:37 -0000 Received: from lyta.akte.de (217.160.134.217) by a.mx.sunsite.dk with SMTP; 18 Feb 2005 00:15:33 -0000 Received: (root@lyta.akte.de) by lyta.akte.de id ; Fri, 18 Feb 2005 01:15:18 +0100 KRecCount: 1 KInfo: virscan ok KInfo: !spam auth Received: from condor.int.spiegl.de (p3E9EB2E3.dip.t-dialin.net [62.158.178.227]) by lyta.akte.de via kasmail (2.9) id ; Fri, 18 Feb 2005 00:15:15 GMT Received: from condor.int.spiegl.de (spiegl@localhost [127.0.0.1]) by condor.int.spiegl.de (8.13.2/8.13.2/Debian-1) with ESMTP id j1I0FCeQ013761 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 18 Feb 2005 01:15:12 +0100 Received: (from spiegl@localhost) by condor.int.spiegl.de (8.13.2/8.13.2/Submit) id j1I0FBMP013759; Fri, 18 Feb 2005 01:15:11 +0100 X-Authentication-Warning: condor.int.spiegl.de: spiegl set sender to zsh.Andy@spiegl.de using -f Date: Fri, 18 Feb 2005 01:15:11 +0100 From: Andy Spiegl To: Bart Schaefer Cc: ZSH User List Subject: Re: parameter expansion or regex question Message-ID: <20050218001511.GA10510@spiegl.de> Mail-Followup-To: Bart Schaefer , ZSH User List References: <20050217030355.GA2943@spiegl.de> <1050217054116.ZM18118@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1050217054116.ZM18118@candle.brasslantern.com> X-PGP-GPG-Keys: mail -s "send pgp" auto@spiegl.de X-Accepted-File-Formats: ASCII OpenOffice .rtf .pdf - *NO* Microsoft files please. X-why-you-shouldnt-use-MS-LookOut: http://www.jensbenecke.de/l-oe-en.php X-warum-man-MS-Outlook-vermeiden-sollte: http://www.jensbenecke.de/l-oe-de.php X-Message-Flag: LookOut! You are using an insecure mail reader which can be used to spread viruses. X-how-to-quote: http://www.afaik.de/usenet/faq/zitieren/ X-stupid-disclaimers: http://goldmark.org/jeff/stupid-disclaimers/ User-Agent: Mutt/1.5.5.1+cvs20040105i X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 Hi Bart, thanks so much for your reply. > setopt extendedglob > CLEANFILENAME="${FILENAME/((#s)|.)q<1-5>(.|(#e))/}" > setopt extendedglob > CLEANFILENAME="${FILENAME/(#b)(#s)(|*).##q<1-5>.#(*|)(#e)/$match[1]$match[2]}" Great! Hm, but both forget a dot if the q? is in the middle, e.g. foo.bar.q1.baz leads to foo.barbaz But no problem, cause I really like this one: > CLEANFILENAME="${(j:.:)${(@)${(@s:.:)FILENAME}:#q<1-5>}}" > > The last splits the file into an array at dots, discards all elements > that look like q<1-5>, then joins the remainder back together again. I actually like the sideeffect you mentioned concerning multiple consecutive dots because it cleans up a "bad" filename. Just out of curiosity, what adjustments would have to be made so that empty array elements aren't ignored and thus multiple dots are kept? > The way you were trying to do it: > > prefix="${${${(M)FILENAME#*q<1-5>.}:-${FILENAME%.q<1-5>*}}%q<1-5>.}" > suffix="${${${(M)FILENAME%.q<1-5>*}:-${FILENAME#*q<1-5>.}}#.q<1-5>}" > CLEANFILENAME="${prefix}${suffix#.}" > > Spelled out: > > prefix="${(M)FILENAME#*q<1-5>.}" > if [[ -n "$prefix" ]]; then prefix="${FILENAME%.q<1-5>*}"; fi > prefix="${prefix%q<1-5>.}" > > suffix="${(M)FILENAME%.q<1-5>*}" > if [[ -n "$suffix" ]]; then suffix="${FILENAME#*q<1-5>.}"; fi > suffix="${suffix#.q<1-5>}" > suffix="${suffix#.}" > > CLEANFILENAME="${prefix}${suffix}" Thanks for even correcting my solution - really interesting! Ah, and now I even understand why your spelled-out version doesn't work! You forgot the ! before the if-condition. :-) Thanks again! Andy. -- o _ _ _ ------- __o __o /\_ _ \\o (_)\__/o (_) -o) ----- _`\<,_ _`\<,_ _>(_) (_)/<_ \_| \ _|/' \/ /\\ ---- (_)/ (_) (_)/ (_) (_) (_) (_) (_)' _\o_ _\_v ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The more things change, the more they remain the same.