Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eihzN-0006Os-LD for pgsql-general@arkaria.postgresql.org; Mon, 05 Feb 2018 14:43:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eihzM-000125-11 for pgsql-general@arkaria.postgresql.org; Mon, 05 Feb 2018 14:43:20 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eihzL-00011u-IV for pgsql-general@lists.postgresql.org; Mon, 05 Feb 2018 14:43:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eihzA-0006Ao-I0 for pgsql-general@postgresql.org; Mon, 05 Feb 2018 14:43:18 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w15Eh6R0030732; Mon, 5 Feb 2018 09:43:06 -0500 From: Tom Lane To: Denisa Cirstescu cc: "pgsql-general@postgresql.org" Subject: Re: Regex Replace with 2 conditions In-reply-to: References: Comments: In-reply-to Denisa Cirstescu message dated "Mon, 05 Feb 2018 13:34:37 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30730.1517841786.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 05 Feb 2018 09:43:06 -0500 Message-ID: <30731.1517841786@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Denisa Cirstescu writes: > Is there a way to specify 2 conditions in regexp_replace? > I need an SQL function that eliminates all ASCII characters from 1-255 t= hat are not A-Z, a-z, 0-9, and special characters % and _ so something li= ke: > SELECT regexp_replace(p_string, E'[' || CHR(1) || '-' || CHR(255) || '&&= [^A-Za-z0-9%_]]', '', 'g')); > But this syntax is not really working. Nope, because there's no && operator in regexes. But I think you could get what you want by using lookahead or lookbehind to combine additional condition(s) with a basic character-class pattern. Something like (?=3D[\001-\377])[^A-Za-z0-9%_] regards, tom lane