public inbox for [email protected]  
help / color / mirror / Atom feed
From: jian he <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: doc regexp_replace replacement string \n does not explained properly
Date: Tue, 21 May 2024 11:24:07 +0800
Message-ID: <CACJufxE5Jp35TSy+Cq+q77ohf1rae0+FrqfMQehJRc2vQM0fWg@mail.gmail.com> (raw)

hi.

https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP
<<<start_quote
The regexp_replace function provides substitution of new text for
substrings that match POSIX regular expression patterns. It has the
syntax regexp_replace(source, pattern, replacement [, start [, N ]] [,
flags ]). (Notice that N cannot be specified unless start is, but
flags can be given in any case.) The source string is returned
unchanged if there is no match to the pattern. If there is a match,
the source string is returned with the replacement string substituted
for the matching substring. 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.
<<<end_quote

<<
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
<<
i think it explained example like:
SELECT regexp_replace('foobarbaz', 'b(..)', 'X\1Y', 'g');

but it does not seem to explain cases like:
SELECT regexp_replace('foobarbaz', 'b(..)', 'X\2Y', 'g');
?


I think it means that 'b(..)', (..) the parenthesized subexpression is
1, the whole expression is (n+1) parenthesized subexpression.
so it is equivalent to
SELECT regexp_replace('foobarbaz', 'b..', 'XY', 'g');






view thread (3+ messages)  latest in thread

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]
  Subject: Re: doc regexp_replace replacement string \n does not explained properly
  In-Reply-To: <CACJufxE5Jp35TSy+Cq+q77ohf1rae0+FrqfMQehJRc2vQM0fWg@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