XQuery replace()函数

replace()函数用给定的字符串替换匹配的输入字符串。

语法

replace($input, $regex, $string)

输入参数

  • $input - 输入字符串。
  • $regex - 正则表达式。
  • $string - 要替换原始字符串的字符串。

示例

XQuery表达式 -

let $input := 'Chapter 1 ... Chapter 2'
return ( replace($input, "Chapter (\d)", "Section $1.0"))

输出结果如下所示 -

Section 1.0 ... Section 2.0

验证结果
要测试上述函数,用上面的XQuery表达式替换books.xqy(在XQuery环境设置章节中有说明)的内容,并执行XQueryTester java程序来验证结果。


上一篇: XQuery正则表达式 下一篇: XQuery自定义函数