From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dan Nessett <dnessett@yahoo.com>
Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: Getting unexpected results from regexp_replace
Date: Sun, 21 Feb 2021 10:50:30 -0500
Message-ID: <3462956.1613922630@sss.pgh.pa.us> (raw)
In-Reply-To: <BED25D59-6AB4-472E-901A-9223CA2C6201@yahoo.com>
References: <BED25D59-6AB4-472E-901A-9223CA2C6201.ref@yahoo.com>
<BED25D59-6AB4-472E-901A-9223CA2C6201@yahoo.com>
Dan Nessett <dnessett@yahoo.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
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, dnessett@yahoo.com
Subject: Re: Getting unexpected results from regexp_replace
In-Reply-To: <3462956.1613922630@sss.pgh.pa.us>
References: <BED25D59-6AB4-472E-901A-9223CA2C6201.ref@yahoo.com> <BED25D59-6AB4-472E-901A-9223CA2C6201@yahoo.com> <3462956.1613922630@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