Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: parameter expansion or regex question
- X-seq: zsh-users 8521
- From: Andy Spiegl <zsh.Andy@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: parameter expansion or regex question
- Date: Fri, 18 Feb 2005 01:15:11 +0100
- Cc: ZSH User List <zsh-users@xxxxxxxxxx>
- In-reply-to: <1050217054116.ZM18118@xxxxxxxxxxxxxxxxxxxxxxx>
- Kinfo: virscan ok
- Kinfo: !spam auth
- Kreccount: 1
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, ZSH User List <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20050217030355.GA2943@xxxxxxxxx> <1050217054116.ZM18118@xxxxxxxxxxxxxxxxxxxxxxx>
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author