Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDbj4-0002jp-FS for pgsql-hackers@arkaria.postgresql.org; Sat, 20 Feb 2021 23:31:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lDbj3-0002mX-BG for pgsql-hackers@arkaria.postgresql.org; Sat, 20 Feb 2021 23:31:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDbj2-0002mQ-Pq for pgsql-hackers@lists.postgresql.org; Sat, 20 Feb 2021 23:31:49 +0000 Received: from anastigmatix.net ([68.171.219.55]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDbiy-0000NK-5a for pgsql-hackers@lists.postgresql.org; Sat, 20 Feb 2021 23:31:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=anastigmatix.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:Cc:References:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=EDitKHgoYIWe4Wl1O6dM2/wUNk5kuHbBEHffzc6GPic=; b=SEJzQTh1RRMDTiBT7zPlbs4oSu Q9xWyAajO1duvOcC39jotxXVq50I2ubyxLpElbY/6TaB6DuL6L+5bNSQkicu/ZlbPijNADkv1zj4Y 1sonqgRPlhLsOrwM/l0OVe2WA9oWJlUpGK7rnu7vEwVGQQK/yP0PHJXKt2+dbHI9mBqCDkbvSyI3y Jrhp2mnnjPNvhIctybhaf5y9K5nqQq88XNN9pGkXH+SqmiLKsdwbzfq6U2O8nSETdqMfV4q8a0GbT nsjDf7q0BXk+Ih+Cw4hVyV2ieVJHNpnYGc6ztjhouK6+1DhMYMBYsZuQ6RwnxBGZyL2rZV2sEp2q6 7m/rBX5g==; Received: from [184.19.31.139] (port=41194) by bay.acenet.us with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lDbiu-007q8M-Ig; Sat, 20 Feb 2021 18:31:41 -0500 Subject: Re: Some regular-expression performance hacking To: Tom Lane , Joel Jacobson References: <1340281.1613018383@sss.pgh.pa.us> <85140bfb-516c-449b-8a03-7930abb42b88@www.fastmail.com> <1813969.1613250697@sss.pgh.pa.us> <913516b8-c3d7-4dea-bf60-d735cf4673f1@www.fastmail.com> <2155152.1613358697@sss.pgh.pa.us> <99f6cbe0-6e58-4e41-add0-977271a5cf84@www.fastmail.com> <2752386.1613595636@sss.pgh.pa.us> <5deabab3-a335-4b57-a046-8a9ad8f2f142@www.fastmail.com> <12e6381c-adc1-4711-a619-864fb8df969c@www.fastmail.com> <2840118.1613671847@sss.pgh.pa.us> <2845172.1613674385@sss.pgh.pa.us> <3028106.1613748380@sss.pgh.pa.us> Cc: pgsql-hackers@lists.postgresql.org From: Chapman Flack X-Enigmail-Draft-Status: N1110 Message-ID: <60319BDB.2040302@anastigmatix.net> Date: Sat, 20 Feb 2021 18:31:39 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <3028106.1613748380@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-OutGoing-Spam-Status: No, score=-95.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bay.acenet.us X-AntiAbuse: Original Domain - lists.postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - anastigmatix.net X-Get-Message-Sender-Via: bay.acenet.us: authenticated_id: chap@anastigmatix.net X-Authenticated-Sender: bay.acenet.us: chap@anastigmatix.net X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 02/19/21 10:26, Tom Lane wrote: >> "foo\nbar".match(/([\w\W]+)/)[1]; >> "foo >> bar" > > Oooh, that's very interesting. I guess the advantage of that over using > the 's' flag is that you can have different behaviors at different places > in the same regex. Perl, Python, and Java (at least) all have a common syntax for changing flags locally in a non-capturing group, so you could just match (?s:.) -- which I guess isn't any shorter than [\w\W] but makes the intent more clear. I see that JavaScript, for some reason, does not advertise that. We don't either; we have (?:groups) without flags, and we have (?flags) but only global at the start of the regex. Would it be worthwhile to jump on the bandwagon and support local flags in groups? We currently give 2201B: invalid regular expression: invalid embedded option on an attempt to use the syntax, so implementing it couldn't break anything someone is already doing. Regards, -Chap