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 1lDsi7-0007bs-FO for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Feb 2021 17:39:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lDsi5-0007Mp-Qi for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Feb 2021 17:39:57 +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 1lDsi5-0007Mi-Js for pgsql-hackers@lists.postgresql.org; Sun, 21 Feb 2021 17:39:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDshz-0000Hn-Az for pgsql-hackers@lists.postgresql.org; Sun, 21 Feb 2021 17:39:57 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 11LHdjKB3467329; Sun, 21 Feb 2021 12:39:45 -0500 From: Tom Lane To: Alvaro Herrera cc: Joel Jacobson , pgsql-hackers@lists.postgresql.org Subject: Re: Bizarre behavior of \w in a regular expression bracket construct In-reply-to: <20210221160651.GA3721@alvherre.pgsql> References: <20210221160651.GA3721@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Sun, 21 Feb 2021 13:06:51 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3467327.1613929185.1@sss.pgh.pa.us> Date: Sun, 21 Feb 2021 12:39:45 -0500 Message-ID: <3467328.1613929185@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > It looks like the interpretation of these other engines is that [\d-a] > is the set of \d, the literal character "-", and the literal character > "a". In other words, the - preceded by \d or \w (or any other character > class, I guess?) loses its special meaning of identifying a character > range. Yeah. While I can see the attraction of being picky about this, I can also see the attraction of being more compatible with other engines. Should we relax this? A quick experiment with perl shows that its opinion is "if the atom before or after a potentially range-defining dash is a character class, then take the dash as an ordinary character". (This confirms Joel's result, and also I found that e.g. [3-\w] treats the dash as a literal character.) > This one I didn't understand: >> ^([\W])$ | pg | I think Joel just forgot to mark that as ERROR. It certainly doesn't work in our engine today (though I'm nearly done with a patch to fix that). regards, tom lane