Re: Regex Replace with 2 conditions
От | David G. Johnston |
---|---|
Тема | Re: Regex Replace with 2 conditions |
Дата | |
Msg-id | CAKFQuwbR=OH5R2QnomGOngZ9FOoc1b7WnWYv64R3VvSu_owqKQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Regex Replace with 2 conditions (Denisa Cirstescu <Denisa.Cirstescu@tangoe.com>) |
Список | pgsql-general |
Is there a way to specify 2 conditions in regexp_replace?
I have written a SQL function that achieves this, but I am not happy with it because it is hard to read and maintain:
-- Eliminates all ASCII characters from 1-255 that are not A-z, a-z, 0-9, and special characters % and _
-- The computed regex expression that is between E[] is CHR(1)-$&-/:-@[-^`{-ÿ].
CREATE OR REPLACE FUNCTION testFunction(p_string CHARACTER VARYING) RETURNS VARCHAR AS $$
SELECT regexp_replace(p_string, E'[' || CHR(1) || '-' || CHR(36) || CHR(38) || '-' || CHR(47) || CHR(58) || '-' || CHR(64) || CHR(91) || '-' || CHR(94) || CHR(96) || CHR(123) || '-' || CHR(255) || ']', '', 'g');
$$ LANGUAGE sql IMMUTABLE;
В списке pgsql-general по дате отправления: