Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Subscripting without temporaries
- X-seq: zsh-users 7342
- From: Lloyd Zusman <ljz@xxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Subscripting without temporaries
- Date: Tue, 13 Apr 2004 12:40:39 -0400
- Cancel-lock: sha1:du6w7sAe49EH3udYHU5qIXh8XNA=
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20040413120053.GA4420@DervishD> <040413082948.ZM20696@xxxxxxxxxxxxxxxxxxxxxxx>
- Sender: news <news@xxxxxxxxxxxxx>
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:
> On Apr 13, 2:00pm, DervishD wrote:
>>
>> I have an array containing strings of this type, one per 'slot':
>>
>> "Some text [particular text] Another text"
>>
>> For each line I want to be able to separate the three parts: the
>> 'Some text', the '[Particular text]', and the 'Another text'.
>
>> Which is the zsh-cool-way of doing the same?
>
> Actually I think backreferences in pattern matching is a pretty cool bit
> already.
>
> However, as you can treat strings as arrays and index them by character,
> and also do slices with pairs of indices:
>
> txt="Some text [particular text] Another text"
> print -l $txt[1,$txt[(i)\[]-2] $txt[(r)\[,(R)\]] $txt[$txt[(I)\]]+2,-1]
This is cool. But what options are necessary in order to make this
work? The commands above produce this output for me:
Some
text
[particular
text]
Another
text
This is the same as what I get with this:
print -l $txt
Thanks.
--
Lloyd Zusman
ljz@xxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author