From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Denisa Cirstescu <Denisa(dot)Cirstescu(at)tangoe(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Regex Replace with 2 conditions |
Date: | 2018-02-05 14:43:06 |
Message-ID: | 30731.1517841786@sss.pgh.pa.us |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Denisa Cirstescu <Denisa(dot)Cirstescu(at)tangoe(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2018-02-05 14:53:24 | Re: Regex Replace with 2 conditions |
Previous Message | Francisco Olarte | 2018-02-05 14:26:46 | Re: Regex Replace with 2 conditions |