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 1lDr0K-0003Xl-Or for pgsql-general@arkaria.postgresql.org; Sun, 21 Feb 2021 15:50:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lDr0J-0003Va-73 for pgsql-general@arkaria.postgresql.org; Sun, 21 Feb 2021 15:50:39 +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 1lDr0I-0003VS-Vk for pgsql-general@lists.postgresql.org; Sun, 21 Feb 2021 15:50:38 +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 1lDr0C-0007z5-D0 for pgsql-general@lists.postgresql.org; Sun, 21 Feb 2021 15:50:38 +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 11LFoU313462957; Sun, 21 Feb 2021 10:50:30 -0500 From: Tom Lane To: Dan Nessett cc: PostgreSQL General Subject: Re: Getting unexpected results from regexp_replace In-reply-to: References: Comments: In-reply-to Dan Nessett message dated "Sun, 21 Feb 2021 08:37:45 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3462955.1613922630.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 21 Feb 2021 10:50:30 -0500 Message-ID: <3462956.1613922630@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Dan Nessett writes: > SELECT user_name, regexp_replace(user_email, E'\(.*\)', '') AS user_emai= l, family_list, street_address, city, state, zip, phone_list, email_list > FROM "household_data" > WHERE email_list !=3D =E2=80=98'; Because you used E'...', the backslashes are eaten by the string literal parser. So the pattern seen by regexp_replace() is just '(.*)', in which the parens are capturing parens not literal characters. Thus it matches the whole string. Personally I'd leave off the E, but if you must use it then double the backslashes. regards, tom lane