zsh-users
 help / color / mirror / code / Atom feed
From: Andy Spiegl <zsh.Andy@spiegl.de>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: ZSH User List <zsh-users@sunsite.dk>
Subject: Re: parameter expansion or regex question
Date: Fri, 18 Feb 2005 01:15:11 +0100	[thread overview]
Message-ID: <20050218001511.GA10510@spiegl.de> (raw)
In-Reply-To: <1050217054116.ZM18118@candle.brasslantern.com>

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.


      reply	other threads:[~2005-02-18  0:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-17  3:03 Andy Spiegl
2005-02-17  5:41 ` Bart Schaefer
2005-02-18  0:15   ` Andy Spiegl [this message]

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=20050218001511.GA10510@spiegl.de \
    --to=zsh.andy@spiegl.de \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@sunsite.dk \
    /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).