Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Parameter Expansion pattern compatibility




On 10 Dec 2008, at 16:19, Stephane Chazelas wrote:

On Wed, Dec 10, 2008 at 03:44:11PM +0100, Jerry Rocteur wrote:
Hi,
[... deleted]
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


OUCH, I tried those with no success so the problems were setopt and the outer ()

I did try kshglob and I didn't think to remove the outer bracket. (I've just tried it on my home system and it works with the outer bracket ?

This all happens in a massive script so I could put setopt kshgob within the function.

As always Stephane, thanks very much .. I really appreciate your help all the time!

As an aside note, how would one do this in standard zsh without the kshglob ?

Cheers,

Jerry


Attachment: smime.p7s
Description: S/MIME cryptographic signature



Messages sorted by: Reverse Date, Date, Thread, Author