From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11948 invoked by alias); 3 Mar 2016 01:25:43 -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: 21342 Received: (qmail 13200 invoked from network); 3 Mar 2016 01:25:41 -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 autolearn=ham autolearn_force=no version=3.4.1 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: zsh-users@zsh.org To: zsh-users@zsh.org From: Emanuel Berg Subject: substitution groups and patterns i replace string (Emacs' \\1 etc.) Date: Thu, 03 Mar 2016 02:08:22 +0100 Message-ID: <87k2lk2ws9.fsf@debian.uxu> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: nl106-137-54.student.uu.se Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:xzsDGBTstaHODzzxNsf+Kwc0IZw= 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? Or, can I feed the match to a function which I define myself which returns the replace string? I think I can bash it together tho it won't be as elegant... I particular, I'm doing text-to-HTML conversion so I want to search for http://... the URLs in the text. To search for them is easy enough but how do I use the result (the match string) to construct the replacement, i.e. ... if, again, the Emacs notation is used to illustrate? -- underground experts united http://user.it.uu.se/~embe8573 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4806 invoked by alias); 3 Mar 2016 09:41:48 -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: 21343 Received: (qmail 15781 invoked from network); 3 Mar 2016 09:41:47 -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 autolearn=ham autolearn_force=no version=3.4.1 X-AuditID: cbfec7f5-f79b16d000005389-ee-56d806d63433 Date: Thu, 03 Mar 2016 09:41:40 +0000 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: substitution groups and patterns i replace string (Emacs' \\1 etc.) Message-id: <20160303094140.705eb3bd@pwslap01u.europe.root.pri> In-reply-to: <87k2lk2ws9.fsf@debian.uxu> References: <87k2lk2ws9.fsf@debian.uxu> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrHLMWRmVeSWpSXmKPExsVy+t/xq7rX2G6EGdz4aGCx4+RKRgdGj1UH PzAFMEZx2aSk5mSWpRbp2yVwZax/f4Op4BZLxfPbn1gbGK8xdzFycEgImEi8XlbTxcgJZIpJ XLi3nq2LkYtDSGApo8S3FcvYIZxpTBKPj5xghnBOM0q0/H3MCOGcYZRY/OwGO8goFgFVibfb y0BGsQkYSkzdNJsRxBYREJVYvmIzO4gtLBAgsW3KXTYQm1fAXmLBymtMIDangIbE6lu3WEHG CAmoS3y6mwcS5hfQl7j69xMTxHX2EjOvnGGEaBWU+DH5HguIzSygJbF5WxMrhC0vsXnNW2YQ G2TMjbu72ScwCs9C0jILScssJC0LGJlXMYqmliYXFCel5xrpFSfmFpfmpesl5+duYoSE8tcd jEuPWR1iFOBgVOLhvdFwPUyINbGsuDL3EKMEB7OSCO9m5hthQrwpiZVVqUX58UWlOanFhxil OViUxHln7nofIiSQnliSmp2aWpBaBJNl4uCUamCs4370pe5HtYjvqhX57PwRTc/mRgYZhl18 eEvz07Omssw/u/7IzrrH3p+wyYL3d5+9vc5i++eyj6sDeNdOW/1wweSV2xecOLJM9fwqqWc8 TUY6UrZbL0vtPGyZG3N8gewU1VD1wxlr1VbcMvStZFVdE2VpJsg7+546/5HXnd/Yoi2D82dt mXFViaU4I9FQi7moOBEAQFoV92ECAAA= On Thu, 3 Mar 2016 02:08:22 +0100 Emanuel Berg wrote: > 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. local -a match mbegin mend if [[ $url = (#b)http://(*) ]]; then print $match[1] fi Works with other forms of pattern matching. pws From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27184 invoked by alias); 6 Mar 2016 06:00:29 -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: 21358 Received: (qmail 22934 invoked from network); 6 Mar 2016 06:00:27 -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 autolearn=ham autolearn_force=no version=3.4.1 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: zsh-users@zsh.org To: zsh-users@zsh.org From: Emanuel Berg Subject: Re: substitution groups and patterns i replace string (Emacs' \\1 etc.) Date: Sun, 06 Mar 2016 06:57:44 +0100 Message-ID: <87a8mccfmv.fsf@debian.uxu> References: <87k2lk2ws9.fsf@debian.uxu> <20160303094140.705eb3bd@pwslap01u.europe.root.pri> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: nl106-137-54.student.uu.se Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:PKn2JjSpzdkobVGntzDUP5AuLh4= 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 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. Perhaps Emacs/sed syntax in this case is something that can be added to zsh? -- underground experts united http://user.it.uu.se/~embe8573 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6850 invoked by alias); 8 Mar 2016 02:52:35 -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: 21374 Received: (qmail 6684 invoked from network); 8 Mar 2016 02:52:34 -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,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=fsajT1fjMmiEPLXZv3W2eOMxziJsrpyEkvF8qZBznzc=; b=swWlm3lNgoJLPsrS5xdNXLM+mMqLtQdMraTwKEcduKjeKFil4dP+ZAOgSaRX4r0+08 4rOYkDzDDnmy4TkzDK6urTXF8LOBatelMo+OCrRyWadLD22/w+kaZzrHgwMg3xKdtI3j b2gohrGhh/YjmVnwsrBLqde+Nr+4akyohkRagWaOZtlMy2IS9LzCRwzuwGamYJ9No0V7 zbfjFAoPW2FtGjFNvLwvAuw2GzH1qG1KE2SiAyjBf9GuKqyUVBAXLICdVHjbR3Dpkpd6 fRMLY+qmgtI9i7HiYThhtrqDT/Ijo/Yrm+iqGx0P6L4tPunoZONv3Ua9Fl6ik6ah4sG0 +TuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=fsajT1fjMmiEPLXZv3W2eOMxziJsrpyEkvF8qZBznzc=; b=YZq1Cunoxgdlnv57WVN2GK0n66ZBL3pB9EFWfwoBnViOhR3wWMuA9p9zBkQYmQeVZs vLm7l00UEwipZ8n3eeVRq9ZX/UeZTm5o1OXjYA5MjRC4dd5uXR/WZSUE28p+uvKgjMyD 0bfAPhYTuQ8ZXZkwgKpOL4779HRo3FUvlF1jHF8BD6WQGrWokW4ydGwMEkaPmE9WP94+ dkhRizTFYZq7iHNa9qIkzbDDSZUalYPzQeftKZLRYLRcepTc9414PvF+ZE/FmT9+2cNL 6Ep4OlUJwqWqfs2kdKFK4itMTDUgVm3DVN54YQdv0lNpU7dOHkz1oeiOOT3eusauupn0 bkpw== X-Gm-Message-State: AD7BkJKnBvN2hVEvdMgRYd4WaC5lpoi4xh598X25NXQRFY7vpnb0ZXkWlDEq59uxeYbrSA== X-Received: by 10.66.193.226 with SMTP id hr2mr38240269pac.20.1457405549768; Mon, 07 Mar 2016 18:52:29 -0800 (PST) From: Bart Schaefer Message-Id: <160307185234.ZM23145@torch.brasslantern.com> Date: Mon, 7 Mar 2016 18:52:34 -0800 In-Reply-To: Comments: In reply to Mikael Magnusson "Re: substitution groups and patterns i replace string (Emacs' \\1 etc.)" (Mar 6, 8:15am) References: <87k2lk2ws9.fsf@debian.uxu> <20160303094140.705eb3bd@pwslap01u.europe.root.pri> <87a8mccfmv.fsf@debian.uxu> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: substitution groups and patterns i replace string (Emacs' \\1 etc.) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Mar 6, 8:15am, Mikael Magnusson wrote: } } % echo ${a//(#b)([aoeui])/${(U)match[1]}} It's actually quite simple to make $1, $2, ... refer to the values in the $match array during ${v//p/r} substitutions. This would make the syntax look very perl-ish, but would mean you can't combine backrefs with expansions of the normal positional parameters. Anyone interested? Discuss? Incidentally, for a fun time consider replacing ${(U)match[1]} with ${(P)match[1]} in that substitution of Mikael's.