pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Denisa Cirstescu <Denisa.Cirstescu@tangoe.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Regex Replace with 2 conditions
Date: Mon, 05 Feb 2018 09:43:06 -0500
Message-ID: <30731.1517841786@sss.pgh.pa.us> (raw)
In-Reply-To: <CY1PR12MB0025991A94F3519B1CB8796BE6FE0@CY1PR12MB0025.namprd12.prod.outlook.com>
References: <CY1PR12MB0025991A94F3519B1CB8796BE6FE0@CY1PR12MB0025.namprd12.prod.outlook.com>

Denisa Cirstescu <Denisa.Cirstescu@tangoe.com> 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 that are not A-Z, a-z, 0-9, and special characters % and _  so something like:
> 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

	(?=[\001-\377])[^A-Za-z0-9%_]

			regards, tom lane




view thread (11+ messages)  latest in thread

Message-ID: <30731.1517841786@sss.pgh.pa.us>
Permalink:  ../30731.1517841786@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/30731.1517841786@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Denisa.Cirstescu@tangoe.com
  Subject: Re: Regex Replace with 2 conditions
  In-Reply-To: <30731.1517841786@sss.pgh.pa.us>
  References: <CY1PR12MB0025991A94F3519B1CB8796BE6FE0@CY1PR12MB0025.namprd12.prod.outlook.com> <30731.1517841786@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox