【问题标题】:Pattern or Format Match in XQuery MarkLogicXQuery MarkLogic 中的模式或格式匹配
【发布时间】:2018-05-17 19:22:17
【问题描述】:

我正在寻找给定的字符串,它必须是*(*) 格式,* 不应该有空格,( 之前没有两个单词。

我正在搜索 MarkLogic DB 以查看给定的列值是否为 [^\s]+\((?!\s)[^()]+(?<!\s)\) 格式,如果不是则用这种格式替换它。

我仍然停留在获取数据,无法编写查询来更新

我正在搜索数据库

    let $query-opts := cts:search(doc(),
      cts:and-query((
        cts:directory-query(("/xyz/documentData/"),"1"),  
            cts:element-query( 
                xs:QName("cd:clause"),  (: <clause> element inside extended for checking query id :)
                cts:and-query((
                    cts:element-attribute-value-query( xs:QName("cd:clause"), xs:QName("tag"), "Title" ),  (: only if the <clause> is of type "Title" :)
                    cts:element-attribute-value-query( xs:QName("cd:xmetadata"), xs:QName("tag"), "Author")

                ))
             )
        ))
for $d in $query-opts
return (
     for $x in $d//cd:document/cd:clause/cd:xmetadata[fn:matches(@tag,"Author")]/cd:metadata_string
     where fn:matches($x/string(), "[^\s]+\((?!\s)[^()]+(?<!\s)\)")
       return 
       (   <documents> {
      <documentId> {$d//cd:cdf/cd:documentId/string()}</documentId>
     }</documents>
       )
     )

它抛出错误无效模式

【问题讨论】:

    标签: regex xquery marklogic


    【解决方案1】:

    fn:matches 函数不支持(?!(?&lt;! 等组修饰符。简化您的模式,并在匹配后捕获误报(如有必要)。

    对你正在尝试做的事情进行有根据的猜测,我认为你正在寻找类似的东西:

    where fn:matches($x, '^.+\([^)]+\).*$') (: it uses parentheses :)
      and fn:not(fn:matches($x, '^[^\s]+\([^\s)]+\)$')) (: but does not comply to strict rules :)
    

    HTH!

    【讨论】:

    • 抱歉回复晚了。非常感谢您的快速回复。它的工作。但在 xyz 123(123_xyz) 等匹配值上失败。括号周围不应该有空格,但可以在单词之间。我试过这样的东西 [^-\s][\w\s*]+[^-\s]([^\s][\w\s*]+[^\s]),这是行不通的任何一个。任何帮助表示赞赏。它不应该以空格开头,也不能以空格结尾。
    • 我建议收集两组值:一组有效,一组无效。对那些尝试了几次正则表达式的人运行隔离测试。如果我没记错的话,我确实注意到上面 cmets 中的正则表达式没有 ` before (, and the match value example you mention has an _, which is not captured by \w`。
    猜你喜欢
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多