简体   繁体   English

Markloigc:在fn:replace中转义正则表达式

[英]Markloigc : Escape regular expression in fn:replace

Can anyone help me how to escape regular expression in fn:replace() 谁能帮助我如何在fn:replace()中转义正则表达式

My actual code look like, 我的实际代码看起来像

Request 请求

let $x := "/SLR/[2009] 3 SLR(R) 0327.xml"
return
(
  fn:replace( $x, $x, "Expected Value")
)

Response : Unexpected response since it has regular expression terms in. 响应 :意外的响应,因为它包含正则表达式项。

/SLR/[2009] 3 SLR(R) 0327.xml

If i escape regular expression manually, i got the result as expected. 如果我手动转义正则表达式,则得到预期的结果。

like, 喜欢,

Request 请求

let $x := "/SLR/[2009] 3 SLR(R) 0327.xml"
return
(
  fn:replace( $x, "/SLR/\[2009\] 3 SLR\(R\) 0327.xml", "Expected Value")
)

Response : 回应

Expected Value

My problem is i cant do manually for 1000 of files i had. 我的问题是我无法手动处理我拥有的1000个文件。

Can any one please help me how to make it easier? 谁能帮助我,使它变得更容易?

The functx library provides a method to do this: functx库提供了执行此操作的方法:

functx:escape-for-regex('[abc]') \[abc\]

http://www.xqueryfunctions.com/xq/functx_escape-for-regex.html http://www.xqueryfunctions.com/xq/functx_escape-for-regex.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM