Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Parameter Expansion pattern compatibility
- X-seq: zsh-users 13574
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Jerry Rocteur <macosx@xxxxxxxxxx>
- Subject: Re: Parameter Expansion pattern compatibility
- Date: Wed, 10 Dec 2008 15:19:36 +0000
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <60710.153.98.68.197.1228920251.squirrel@xxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: Jerry Rocteur <macosx@xxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <60710.153.98.68.197.1228920251.squirrel@xxxxxxxxxxxxxxxxxxx>
On Wed, Dec 10, 2008 at 03:44:11PM +0100, Jerry Rocteur wrote:
> Hi,
>
> I have one that I can sovle by using perl inside my zsh script but if anyone has time, I'm curious as to why it fails
> on zsh..
>
> echo $ZSH_VERSION
> 4.2.6
>
> Given a list of strings like this
>
> set -A userId p0btu pabtu p11btu p11eb41 rs0bt2 jro dri
>
> I would like to see btu btu btu eb41 bt2 jro dri
>
> if string begins with any case prt and is followed by one and one only [0-9] or [a-z] folowed by any mumber of digits.
> Remove everything up to the last digit.
>
> In ksh we did it like this ${userId[$i]##([pPRrTt]@([0-9]|[a-z])*([0-9]))}
That's ksh globbing syntax (except for the outer (...)). To
enable it in zsh, you need setopt kshglob.
The zsh equivalent of @(...) is (...), the equivalent of *(x) is
x# (with extendedglob).
~$ setopt kshglob; echo ${userId##[pPRrTt]@([0-9]|[a-z])*([0-9])}
btu btu btu eb41 bt2 jro dri
~$ setopt nokshglob extendedglob; echo ${userId##[pPRrTt]([0-9]|[a-z])[0-9]#}
btu btu btu eb41 bt2 jro dri
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author