What is the error of using postgres regexp_replace to 12?

Before you bring the essence in the form of examples, please do NOT preterites to the meaning, only to the mechanics of the function directly.

So examples.
How-to cut out the tags (not preterites to the point, please):
SELECT regexp_replace('foo <a>123</a> bar <a>123</a> baz', '<a>.*?</a>', ", 'g');
-- foo bar baz

Everything is OK as expected.

A little complicate:
SELECT regexp_replace('foo <a, X>123</a> bar <a Y>123</a> baz', '<a [XY]>.*?</a>', ", 'g');
-- foo bar baz

Everything is OK as expected.

Change square brackets to round:
SELECT regexp_replace('foo <a, X>123</a> bar <a Y>123</a> baz', '<a (X|Y)>.*?</a>', ", 'g');
-- foo baz

Why bar was eaten?

Version of posgres: 12. Documentation on the function here: https://postgrespro.ru/docs/postgrespro/12/functio...
April 7th 20 at 10:51
1 answer
April 7th 20 at 10:53
Solution
The answer is found in IRC posgres and documentation.
Need to write this:

SELECT regexp_replace('foo <a, X>123</a> bar <a Y>123</a> baz', '<a (X|Y){1,1}?>.*?</a>', ", 'g');

Find more questions by tags PostgreSQLRegular expressions