From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id QKSxBfAB12GnMgAAgWs5BA (envelope-from ) for ; Thu, 06 Jan 2022 15:51:28 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id OGYTA/AB12HgFwAA9RJhRA (envelope-from ) for ; Thu, 06 Jan 2022 15:51:28 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 625003538F for ; Thu, 6 Jan 2022 15:51:27 +0100 (CET) Received: from localhost ([::1]:47966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5U6w-0002f0-5B for larch@yhetil.org; Thu, 06 Jan 2022 09:51:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5Tzl-00042r-Nk for help-guix@gnu.org; Thu, 06 Jan 2022 09:44:01 -0500 Received: from [2a02:c205:2020:6054::1] (port=38580 helo=tobias.gr) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5Tzi-0003EO-Hn for help-guix@gnu.org; Thu, 06 Jan 2022 09:44:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=2018; bh=zzQjokRvoytUb qeGOBmMZjGivdq7yfvz3YF6poFHASI=; h=in-reply-to:date:subject:cc:to: from:references; d=tobias.gr; b=Al/A1sgwdfy2gr2WuZvTFXmt01wBLXAhYjD4lX 7T7+XH8r5dkvYtPDz+ws/9LI4xYGtrzYWxw1409x0b1h8GzR3CMLPxd7hrdk0PQ+MNQqvm kja8HhipcepabG+11fOLkml6grxGJXMH5bHM17lwz7JAESQr+le7GadFc93KPD0S2vxw5v qWMJgzmL13BNA/pCVqokaAf+P3P7CUNg8f9Fow/6OSzRNQyUKtIO41CoJIlcFG9GbUUVke VsiODOGg0Pz5cW+mXIIy+mULpWPKFaC4XBuNDwAz5a29WliQxa9ScaqiU5288600+qDdAf GZt4u79t+vcMV+OPP1UptC+Q== Received: by submission.tobias.gr (OpenSMTPD) with ESMTPSA id d108908e (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Thu, 6 Jan 2022 14:43:54 +0000 (UTC) References: From: Tobias Geerinckx-Rice To: Mortimer Cladwell Cc: help-guix@gnu.org Subject: Re: Help needed with substitute* command Date: Thu, 06 Jan 2022 14:50:15 +0100 In-reply-to: BIMI-Selector: v=BIMI1; s=default; Message-ID: <87k0fchqjz.fsf@nckx> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a02:c205:2020:6054::1 (failed) Received-SPF: pass client-ip=2a02:c205:2020:6054::1; envelope-from=me@tobias.gr; helo=tobias.gr X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-guix@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-guix-bounces+larch=yhetil.org@gnu.org Sender: "Help-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641480687; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=zzQjokRvoytUbqeGOBmMZjGivdq7yfvz3YF6poFHASI=; b=VcMpgEOdJp99eNKjHVXexXLKtQbiy2g2QQqmV/JfWpxRXl83hFE0S4tJv288U3yEwfPRmP EL/nPVMqX57OmBK20EFDEp5mCX+DCMo2IFzzisITk8ATr3f3uWBquqrIlA076cQyu/oJnt Cbz/ldwzJrGT8adIERxIdsY4SdSevKiw1JZCdczmlZv1ealxdiaF5tSID0J2V64xvQfVq9 HFPuLp7YkCoi8Vke+s1Ck2wujfIZ331B1ASxEpYxH263hRH7lcAqB/zKl30Nr+HddgrvTa nfYCfiPQUEx4o1c6jgo3sXcoehzZofWRPIQdeheWoRiGZgKxLaFGw9zTt7cxsA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641480687; a=rsa-sha256; cv=none; b=HZ/u/W43iT+GHlfRn+wat3icYNcdYUkQu66XTJtXnX9xpspGRLkuouaTtr7sNuqVpend8a tXrtXdvRKjXtl3idXz8RlEvqkVgXRimxMKULdHvogH4T4PGyzSWhowJLy9wr6ZB5MSqUot w6uIR8KDXRN74sDiZbqYonJxFyHEougkU4OIGbzwNGQM86cU0l38UuP/5ILTv4oDeWMEZn AC/qL7J8ABMhT6NHhseAuG7XkcFn3GfJO6Su+GrmEjb9VwHnYV7ifIVaobvkmf2ESou3Fy KmDQMGWfL3kGXMu4t6Mq1E6t7T0WmRroPEeQh2KiXSqBWuL7OseBoQzHBK9TEQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=tobias.gr header.s=2018 header.b="Al/A1sgw"; dmarc=pass (policy=reject) header.from=tobias.gr; spf=pass (aspmx1.migadu.com: domain of "help-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="help-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -5.90 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=tobias.gr header.s=2018 header.b="Al/A1sgw"; dmarc=pass (policy=reject) header.from=tobias.gr; spf=pass (aspmx1.migadu.com: domain of "help-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="help-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 625003538F X-Spam-Score: -5.90 X-Migadu-Scanner: scn1.migadu.com X-TUID: WXGBzssXVv87 --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Hullo Mortimer, I hope this answer isn't too basic for you. This input: Mortimer Cladwell =E5=86=99=E9=81=93=EF=BC=9A > ---input.txt(2)------- > foo(abc)bar(def) does not match the extended regular expression: > "foo([a-z]+)bar(.*)$" This would: ---input.txt(3)------- foolishbarista result: bazlishista I'm not the one to either write or recommend a tutorial on=20 extended regular expressions, but you'll find plenty on the 'net.=20 There's also =E2=80=98info (grep)Regular Expressions=E2=80=99 which might b= e good.=20 These things aren't specific to Guile, although a few dialects=20 exist, and I think Guile uses the POSIX one. The differences are=20 quite small. In this specific example > ("foo([a-z]+)bar(.*)$" all letters end) the first string is an extended regular expression. It will match a literal =E2=80=98foo=E2=80=99 anywhere on a line, followed = by 1 or=20 more lowercase letters, followed by a literal =E2=80=98bar=E2=80=99, follow= ed by=20 anything until the end of the line. It will NOT match anything with =E2=80=98()=E2=80=99 brackets in it, like y= our=20 original input.txt(2). The brackets are regexp syntax used for=20 grouping and capturing. If an optional variable name follows the regexp, it will be set to=20 the complete match. Here, that is =E2=80=98all=E2=80=99, which in our exam= ple=20 will contain "foolishbarista". It's not used here. In practice, this variable would be named =E2=80=98_=E2=80=99 to indicate t= hat=20 it's unimportant: (("foo([a-z]+)bar(.*)$" _ letters end) (string-append "baz" letters end)) but the author of the manual example thought that =E2=80=98all=E2=80=99 wou= ld be=20 more clear. Each subsequent optional variable will be set to the content=20 matched by () groups. Here, =E2=80=98letters=E2=80=99 will be set to whate= ver=20 matched =E2=80=98[a-z]+=E2=80=99, and =E2=80=98end=E2=80=99 to whatever mat= ched =E2=80=98.*=E2=80=99. In our example =E2=80=98letters=E2=80=99 is "lish" and =E2=80=98end=E2=80= =99 is "ista". This is powerful, because we can construct arbitrary strings at=20 run time based that can differ significantly for each line that=20 matches the same regexp: > (string-append "baz" letter end) is just Scheme code that uses the captured variables above,=20 without hard-coding assumptions about what was matched. footbarnacles =E2=86=92 baztnacles foodiebarmaid =E2=86=92 bazdiemaid =E2=80=A6 Minutes of fun. This special meaning of =E2=80=98()=E2=80=99 in extended rexeps means that = if you=20 would want to match: ---input.txt(4)------- fo(bizzle) you'd write: "fo\\(bizzle\\)" Because "\" in a string *also* has special meaning to Guile=20 itself, we have to write "\\(" if we want the regexp engine to see=20 "\(". > Is the letters/letter in the manual a typo? If I use letter I=20 > get > "...unbound variable..." Yes, that was a typo, both names should match. I've fixed it.=20 Thanks for apparently being the first to test this snippet! Kind regards, T G-R --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iIMEARYKACsWIQT12iAyS4c9C3o4dnINsP+IT1VteQUCYdcAUA0cbWVAdG9iaWFz LmdyAAoJEA2w/4hPVW15zjYA/icDs7l8dtB2MnjnDN1+pW9RrPJjh6ufosDlfl+o JFstAQDQj3ls7oGptrA5gbGsRMSVTxeOre8YdS2WCGWfU0avAA== =gmIc -----END PGP SIGNATURE----- --=-=-=--