Обсуждение: [DOCS] can't be both non-capturing and still capture

Поиск
Список
Период
Сортировка

[DOCS] can't be both non-capturing and still capture

От
srn@coolheads.com
Дата:
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/9.6/static/index.html
Description:

In postgresql-doc-9.5/html/functions-matching.html#POSIX-MATCHING-RULES:

<PRE
CLASS="SCREEN"
>SELECT regexp_matches('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
<I
CLASS="LINEANNOTATION"
>Result: </I
><SAMP
CLASS="COMPUTEROUTPUT"
>{abc,01234,xyz}</SAMP
></PRE
>

Here, the whole regexp is non-capturing, right, so how can the result be
reported as shown?

The previous two warmup examples do not have the surrounding
non-capturing-group markup.  Looks to me like that markup should not appear
here, either.

Re: [DOCS] can't be both non-capturing and still capture

От
Tom Lane
Дата:
srn@coolheads.com writes:
> Here, the whole regexp is non-capturing, right, so how can the result be
> reported as shown?

No, the outer parens are non-capturing, but the ones inside them still
are capturing parens.

Perhaps it would clarify matters if you tried it with plain outer parens:

=# SELECT regexp_matches('abc01234xyz', '((.*?)(\d+)(.*)){1,1}');
       regexp_matches
-----------------------------
 {abc01234xyz,abc,01234,xyz}
(1 row)

In this case we get a report from each of the four sets of capturing
parens.  Or another example:

=# SELECT regexp_matches('abc01234xyz', '((?:.*?)(\d+)(.*)){1,1}');
     regexp_matches
-------------------------
 {abc01234xyz,01234,xyz}
(1 row)

Outer parens capture, first inner set don't, other two inner sets do.

            regards, tom lane