public inbox for [email protected]
help / color / mirror / Atom feedFrom: David G. Johnston <[email protected]>
To: jian he <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: doc regexp_replace replacement string \n does not explained properly
Date: Mon, 20 May 2024 20:44:04 -0700
Message-ID: <CAKFQuwYG5+gGjFLoAcYk8BBW4EGY6i-NQG7N2FqxyAp8eunR9A@mail.gmail.com> (raw)
In-Reply-To: <CACJufxE5Jp35TSy+Cq+q77ohf1rae0+FrqfMQehJRc2vQM0fWg@mail.gmail.com>
References: <CACJufxE5Jp35TSy+Cq+q77ohf1rae0+FrqfMQehJRc2vQM0fWg@mail.gmail.com>
On Monday, May 20, 2024, jian he <[email protected]> wrote:
> hi.
>
> https://www.postgresql.org/docs/current/functions-
> matching.html#FUNCTIONS-POSIX-REGEXP
>
>
> If there is a match,
> the source string is returned with the replacement string substituted
> for the matching substring.
>
This happens regardless of the presence of parentheses.
>
> The replacement string can contain \n,
> where n is 1 through 9, to indicate that the source substring matching
> the n'th parenthesized subexpression of the pattern should be
> inserted, and it can contain \& to indicate that the substring
> matching the entire pattern should be inserted.
Then if the replacement text contains ā\nā expressions those are replaced
with text captured from the corresponding parentheses group.
> <<
> i think it explained example like:
> SELECT regexp_replace('foobarbaz', 'b(..)', 'X\1Y', 'g');
global - find two matches to process.
foobarbaz
fooX\1YX\1Y
fooXarYXazY
>
> but it does not seem to explain cases like:
> SELECT regexp_replace('foobarbaz', 'b(..)', 'X\2Y', 'g');
>
>
foobarbaz
fooX\2YX\2Y
fooX{empty string, no second capture group}YX{empty}Y
fooXYXY
The docs are correct, though I suppose being explicit that a missing
capture group results in an empty string substitution instead of an error
is probably warranted.
David J.
view thread (3+ messages)
reply
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: doc regexp_replace replacement string \n does not explained properly
In-Reply-To: <CAKFQuwYG5+gGjFLoAcYk8BBW4EGY6i-NQG7N2FqxyAp8eunR9A@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox