Re: Getting unexpected results from regexp_replace

From: Dan Nessett <dnessett(at)yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Getting unexpected results from regexp_replace
Date: 2021-02-21 16:05:31
Message-ID: A1C0C07D-833D-465F-8894-10E9B64EDA90@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks. Doubling the backslashes did the trick. I tried to use the original expression without the E, but postgres threw an error and said to use the ā€œEā€ version of the pattern.

Dan

> On Feb 21, 2021, at 8:50 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Dan Nessett <dnessett(at)yahoo(dot)com> writes:
>> SELECT user_name, regexp_replace(user_email, E'\(.*\)', '') AS user_email, family_list, street_address, city, state, zip, phone_list, email_list
>> FROM "household_data"
>> WHERE email_list != ā€˜';
>
> Because you used E'...', the backslashes are eaten by the string literal
> parser. So the pattern seen by regexp_replace() is just '(.*)', in
> which the parens are capturing parens not literal characters. Thus it
> matches the whole string.
>
> Personally I'd leave off the E, but if you must use it then double the
> backslashes.
>
> regards, tom lane
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Lewis 2021-02-21 17:14:04 Re: Please help to improve SELECT JOIN performance, EXPLAIN ANALYZE attached
Previous Message Tom Lane 2021-02-21 15:50:30 Re: Getting unexpected results from regexp_replace