From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id qFLhDyMD12ENUAAAgWs5BA (envelope-from ) for ; Thu, 06 Jan 2022 15:56:35 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id zFGcCCMD12FkIgEAG6o9tA (envelope-from ) for ; Thu, 06 Jan 2022 15:56:35 +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 C5ACB2469A for ; Thu, 6 Jan 2022 15:56:34 +0100 (CET) Received: from localhost ([::1]:60204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5UBt-0002kR-29 for larch@yhetil.org; Thu, 06 Jan 2022 09:56:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5U97-0000K0-4Q for help-guix@gnu.org; Thu, 06 Jan 2022 09:53:41 -0500 Received: from [2607:f8b0:4864:20::334] (port=39477 helo=mail-ot1-x334.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n5U95-0005WL-6W for help-guix@gnu.org; Thu, 06 Jan 2022 09:53:40 -0500 Received: by mail-ot1-x334.google.com with SMTP id p8-20020a9d7448000000b005907304d0c5so3316797otk.6 for ; Thu, 06 Jan 2022 06:53:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mNsg6EitROtukNELX1nVzw2QMcdXtMgh79I5jwq/bWM=; b=D4pzoXyZRWx1Zvh0fFmV8nrxoQx9yIbGhIEJU0+zFgDTZRfu/fTNGxTW6qZbPfTxCu pb7z8kU0nI/IwkwrQVxhf1hCTbozuqGEgIz/M/W8lGCgrrucDVIWFwK30BZmdZpvhilO mjt1z9sv7WjBCfIZ+6cUU3LTp6hIuJk1QWQWjE+LJ6ECi/ZsYa0+r17WZEGkiHGzfgRH gvCPlrl4rTw6fXRoVosHsSzNdMSbFVNM5smIIeT11tJTBbvXIegSV6T/mQvyug+6VH7m 41lD1ds7ic+BJjeJWXhko9/dhgxkuPl7ioNM9ZExv55PyN4J5QxPNIhObNJU2IPpLIMH b51A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mNsg6EitROtukNELX1nVzw2QMcdXtMgh79I5jwq/bWM=; b=SlWaMjGvJOBug4yv9Z+JCvkuXFGkaQlFSpBLMPXu6mhDAk4lTbCYt19GEKdb0MQcIi gt574tzI8MAHKytr6y9EEjLBcI6Fi3yB2f6wgMJ3qnvBZoR8wfb2dSoW90PhJ1fq+LuG aS0ImVtlymwjA70rUVimsftovQXVJT4/QEkr6y25uv/Nlwh76cFmywEEzqrCpR85jedc yxLlZTvyPPcfmhfv12otII9FSRenzPaDdTRaia13P6Ma2jTPxbqr3K4ttx+Bx1Nlf6VI DDLbbE6gpo4zitZIFf14iQeCrvrccssoQWgfe+SNzLlFRpSpuyiIfOm+s5p9vM0QHqdC taOQ== X-Gm-Message-State: AOAM531ZepiaUCAHQZqlP/8n4Wlc9ZJp+ZG6Ay9Ls5oV4Rx7F2v2SizP RFN6z5BibxGFMcxi3Fg5VlGq8eyTlfQxxrIMuRIZq5D4 X-Google-Smtp-Source: ABdhPJwRioudywelxFGcTSOJ6tZL59XBNphR6byD5HH5qgQifFsRCpyoNQKTymQQrHJAF5M7a+xs4Qud0x61serIEEg= X-Received: by 2002:a9d:2d81:: with SMTP id g1mr42771889otb.25.1641480818192; Thu, 06 Jan 2022 06:53:38 -0800 (PST) MIME-Version: 1.0 References: <87k0fchqjz.fsf@nckx> In-Reply-To: <87k0fchqjz.fsf@nckx> From: Mortimer Cladwell Date: Thu, 6 Jan 2022 09:53:26 -0500 Message-ID: Subject: Re: Help needed with substitute* command To: Tobias Geerinckx-Rice X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::334 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::334; envelope-from=mbcladwell@gmail.com; helo=mail-ot1-x334.google.com 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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: , Cc: help-guix 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=1641480994; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=RgEf5fuZvOevFuYs8pVxb9U4bXJ8Pawth3G2TIBnXfc=; b=N1tFZofJA6xVTd+xP9c5VcNM8JmWbWwx2zvQp9PvZ8hyzpqgBhrrSzp8WgKlMcBD0PB5+v 2KBglTtNe9Mo10qawWUk0s6wsJGKxqlwL+lD62Fvj9jIf2cgDygLjmsT+UNggD1BDLYk0f mlpKPDbNOJ+sYwuCiWnYypwbzEvwFiokxFojn3FhsCZMy9Z/VKyMzaGsOkvl5t/Y/oKmci rL/pKwSZsmfZdHp6zl/9MWgS5Ylh/ezDxVEFFUYgFbQ86MMYN4CIBNWkQ5fk+cNEodmYkJ G44KWh7TFJnj6JM7QZI+1oM9VTaT6OFE3WD8l1hIow1+C5yR5RtLDjgBxYcHlQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641480994; a=rsa-sha256; cv=none; b=SWYvcBQjK05VmkMyOgZUzenyTQ1sAUpsjd+aez8sXWiBhjjIzbj+AjwEwNL+7WK3w148M/ w/s8AfzDVkE9NqHQK8rwup5UnjSUfNbnhuwZtL0CFzlJBrZQ1ltdBBKrlHM0LFmPGh/xCZ K0TqJCd3gygzGMj9Fz2boeazaLoV0T8HJaZOzvnv4kAEgny6dAGKbXa3OPSWqkKj5c8ldD 0O+fjC80Xsm64fwRAK/x70WiLbmhvde6UD9TftQ6OIHCy4Tnkyykyu5UX5l7ICHQpN/KU+ rPBYZqvd3jNZicjjs7mbokvogdnluuDa1sTL1sPv8zDxQVmRi5cD5nsAIFV8BA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=D4pzoXyZ; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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: -2.50 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=D4pzoXyZ; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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: C5ACB2469A X-Spam-Score: -2.50 X-Migadu-Scanner: scn0.migadu.com X-TUID: N/ampQfKMApQ Thanks for the detailed explanation Tobias. Guess I need to brush up on regular expressions. Mortimer On Thu, Jan 6, 2022 at 9:43 AM Tobias Geerinckx-Rice wrote: > 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 > extended regular expressions, but you'll find plenty on the 'net. > There's also =E2=80=98info (grep)Regular Expressions=E2=80=99 which might= be good. > These things aren't specific to Guile, although a few dialects > exist, and I think Guile uses the POSIX one. The differences are > 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, followe= d by 1 or > more lowercase letters, followed by a literal =E2=80=98bar=E2=80=99, foll= owed by > anything until the end of the line. > > It will NOT match anything with =E2=80=98()=E2=80=99 brackets in it, like= your > original input.txt(2). The brackets are regexp syntax used for > grouping and capturing. > > If an optional variable name follows the regexp, it will be set to > the complete match. Here, that is =E2=80=98all=E2=80=99, which in our ex= ample > will contain "foolishbarista". It's not used here. > > In practice, this variable would be named =E2=80=98_=E2=80=99 to indicate= that > 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 w= ould be > more clear. > > Each subsequent optional variable will be set to the content > matched by () groups. Here, =E2=80=98letters=E2=80=99 will be set to wha= tever > matched =E2=80=98[a-z]+=E2=80=99, and =E2=80=98end=E2=80=99 to whatever m= atched =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 > run time based that can differ significantly for each line that > matches the same regexp: > > > (string-append "baz" letter end) > > is just Scheme code that uses the captured variables above, > 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 tha= t if you > would want to match: > > ---input.txt(4)------- > fo(bizzle) > > you'd write: > > "fo\\(bizzle\\)" > > Because "\" in a string *also* has special meaning to Guile > itself, we have to write "\\(" if we want the regexp engine to see > "\(". > > > Is the letters/letter in the manual a typo? If I use letter I > > get > > "...unbound variable..." > > Yes, that was a typo, both names should match. I've fixed it. > Thanks for apparently being the first to test this snippet! > > Kind regards, > > T G-R >