Understand the XPath expression

Viewed 29

I want to understand the below XPath expression

fn:replace ($var,concat('^.*',fn:replace('.','(\.|\[|\]|\\|\||\-|\^|\$|\?|\*|\+|\{|\}|\(|\))','\\$1')),'')

I understand
\ denotes an escape character
| denotes OR
. denotes any single character

But I am confused with the use of \$1 here. What is it referring to?

1 Answers

$1 is a back-reference.

The goal of the expression is to replace any regex meta-character (., [, ], and so on) with an escaped version of that character.

Related