'Escape characters used in plsql packages

Is there any meaning for '\2' in plsql. I am seeing the below expresion is used quite a lot.

regexp_replace(variable, '[*]','\2')


Solution 1:[1]

In the expression Regexp_replace(variable, '[*]', '\2') then \2 is a back-reference referring to the second capturing group in the regular expression.

However, in your expression, the '[*]' regular expression does not have any () capturing groups so it will not match anything and would just replace each * character with nothing.

If you had Regexp_replace(variable, '(abc)(def)(ghi)', '\2') then the capturing groups will match abc in the first group, def in the second group and then ghi in the third capturing group and will replace the entire abcdefghi match with the contents of the second capturing group, which is only def.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MT0