The following regex simply extracts a part of the matched text using the backreferencing numbers:
SELECT regexp_replace('ABCDEFGHIJ','(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)','\2');
B
Run Code Online (Sandbox Code Playgroud)
But how to backreference beyond the ninth matched substring?
The following won't work (returns the first match + 0), neither will the use of $10 or ${10}:
SELECT regexp_replace('ABCDEFGHIJ','(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)','\10')
A0
Run Code Online (Sandbox Code Playgroud)
Note: this example was simplified for clarity, and would of course not necessitate going beyond backreference 9.
根据文档,模式字符串中支持大于 9 的反向引用:
\mnn(其中m是非零数字,并且nn是更多数字,并且小数值mnn不大于迄今为止看到的右捕获括号的数量)对第mnn'th 子表达式的反向引用
但是,似乎它们在以下位置的替换字符串中不受支持regexp_replace:
该
replacement字符串可以包含\n,其中n1 到 9,以指示n应插入与模式的第 ' 个带括号的子表达式匹配的源子字符串...