Syntax for fn:matches() is based on W3C XML Schema Language regular expressions:
fn:matches()
Syntax for fn:replace() is based on W3C XML Schema Language regular expressions plus $N in replace patterns to indicate the Nth match.
fn:replace()
$N