Details
Description
select regexp_replace('1 foo and bar', '(\\d+) foo and (\\d+ )?bar', '\\1 this and \\2that')
expected result: 1 this and that
actual result: 1 this and 2that
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Thinking about it, it sort of makes sense.
the second group does not match to an empty value, it is undefined at all; so the ambiguous sequence backslash-backslash-2 defaults to '2'.
It's counter-intuitive though.
My quick search through PCRE documentation hasn't found anything saying whether it's intentional, so I'm assigning it to Alexander Barkov to confirm (or not).
Or, maybe there is a flag that controls it, I haven't found one either.