Re: Regex Replace with 2 conditions

Поиск
Список
Период
Сортировка
От Francisco Olarte
Тема Re: Regex Replace with 2 conditions
Дата
Msg-id CA+bJJbz2QG8Wg037OBxr0TPg1+-7YkwK5ikpY7tAoETCXmOZKw@mail.gmail.com
обсуждение исходный текст
Ответ на Regex Replace with 2 conditions  (Denisa Cirstescu <Denisa.Cirstescu@tangoe.com>)
Список pgsql-general
Denisa:

On Mon, Feb 5, 2018 at 2:34 PM, Denisa Cirstescu
<Denisa.Cirstescu@tangoe.com> wrote:
> 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:

Are you aware ASCII is a SEVEN bit code ?

And now, why don't you just write the negated condition, maybe
throwing in a null to avoid it? Do you have codes above 255 which you
do not need replacing?

I.e., something like

SELECT regexp_replace(p_string, E'[^A-Za-z0-9%_]', '', 'g'));

This will also zap \0 and all chars >255 if you are using unicode, if
this is not a problem that's all there is to it.

If you are using it you could throw a null plus a character range from
256 to the largest one, but I doubt this is useful. Which is the
character set of your source data? ( It can NOT be ascii if you are
worried about 128-255, but is it a single byte one or is it unicode or
something wide ? )

Also, it may perform a bit faster if you throw a + after the character
class ( for >1 char runs ).

Francisco Olarte.


В списке pgsql-general по дате отправления:

Предыдущее
От: Denisa Cirstescu
Дата:
Сообщение: Regex Replace with 2 conditions
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Regex Replace with 2 conditions