From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 543 invoked by alias); 6 Mar 2016 07:15:44 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21359 Received: (qmail 1316 invoked from network); 6 Mar 2016 07:15:42 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to; bh=HjOCYwLRbUMNICol627ANEkn3Wn8JZTd5RXRwR2El8U=; b=fyL0ONelDHBIHM7QSpMdMlOg1YD71Zkv1Bre7kGUg8PK9dm5+XccQqldDogSakyglE nkU36s4y+koJW9k8XXK4Jbng2VCRI9Cj/uADJYRhWyTAfxbDd5zUdfT5M2oB5Y6TKwN/ pFSCA3dWXrb5L49mUa2KoDIAsy4L7oGr3GGlsvhl8oHPxZ1qJRa3rudxihU8CTQwmvVp LrNwL0jQo8CjIfjQofmlbUSjxgoWSlWztlnbo62/d1v7leG0FPJtc0yX5NhXSVlG5KS+ KaUuroDQbHBJ/HyuLKgQagEHGDnFDpyTTmFugn0Z1PA9tWg3p6zSihMXCvDfzEYub7QA iQaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to; bh=HjOCYwLRbUMNICol627ANEkn3Wn8JZTd5RXRwR2El8U=; b=b2EIbN54CaJ2RrX8WsYdZuf4iDdPfd9MK8moT41gK+N+RxF7LOAnlzmp6uwYTRfAug IELCDnut8XZy60XKdJTxMmSX8e5aQG0IgaC0V/0LGjr2uQBWhEkL0Mojnk8oOeB2Dovw 3YHyB8RY2FGVc6gBMKVMm9D9t0O8x3+mISEX6BSAwKgzkS7rfHmpMEIw3RZz4C9TrIEm HCkaV/24kdamNhx1cuT5FQGBZ8ybNEZIW9TYfBvygoCFWLw6jLRFV45LXqapKWQPWWB0 RK8FVPm/j9M1aesSutnwqWs86RW8Dgwl0tppi4BrsnqfDN/FjTHrsasKRblDg+lBHXcs sEvg== X-Gm-Message-State: AD7BkJIJOWRaTI/40iVQEziQs3f/PhNXsjL+5VmVrfvpxLzfufDSA9vNbMqwiVM7sEgmLO7zaCHr6R/TuvP4vQ== MIME-Version: 1.0 X-Received: by 10.140.19.147 with SMTP id 19mr20840403qgh.70.1457248538516; Sat, 05 Mar 2016 23:15:38 -0800 (PST) In-Reply-To: <87a8mccfmv.fsf@debian.uxu> References: <87k2lk2ws9.fsf@debian.uxu> <20160303094140.705eb3bd@pwslap01u.europe.root.pri> <87a8mccfmv.fsf@debian.uxu> Date: Sun, 6 Mar 2016 08:15:38 +0100 Message-ID: Subject: Re: substitution groups and patterns i replace string (Emacs' \\1 etc.) From: Mikael Magnusson To: Zsh Users Content-Type: text/plain; charset=UTF-8 On Sun, Mar 6, 2016 at 6:57 AM, Emanuel Berg wrote: > Peter Stephenson writes: > >>> When I do substitution, can I do groups and >>> patterns like in Emacs with \\1, \\2 to reference >>> the particular matches, and thus construct the >>> replace string out of them any way I like? >> >> You do it with $match, and if you need to refer to >> positions in the original string, $mbegin and $mend. >> See the description of the (#b) pattern in the >> zshexpn manual page. > > I have now checked out the zshexpn(1) man page but the > examples there are very complicated! > >> local -a match mbegin mend >> >> if [[ $url = (#b)http://(*) ]]; then print $match[1] >> fi % a="> Thanks, but this syntax is very bulky compared to > Emacs and sed. How it is supposed to be used for > a stream of text or a variable with several hit > instances? I'm not saying it can't be done only > compared to Emacs (and sed) it seems > unnecessarily complicated." % echo ${a//(#b)([aoeui])/${(U)match[1]}} > ThAnks, bUt thIs syntAx Is vEry bUlky cOmpArEd tO > EmAcs And sEd. HOw It Is sUppOsEd tO bE UsEd fOr > A strEAm Of tExt Or A vArIAblE wIth sEvErAl hIt > InstAncEs? I'm nOt sAyIng It cAn't bE dOnE Only > cOmpArEd tO EmAcs (And sEd) It sEEms > UnnEcEssArIly cOmplIcAtEd. -- Mikael Magnusson