I'm looking at this example from: https://docs.marklogic.com/10.0/rest:matching-request
Specifically, this code:
xquery version "1.0-ml";
import module namespace rest="http://marklogic.com/appservices/rest"
at "/MarkLogic/appservices/utils/rest.xqy";
declare option xdmp:mapping "false";
let $options :=
<options xmlns="http://marklogic.com/appservices/rest">
<request uri="^/shakespeare/(.+)/(.+)" endpoint="/redirect.xqy">
<uri-param name="__ml_redirect__">/$1/$2</uri-param>
</request>
<request uri="^/shakespeare/(.+)" endpoint="/redirect.xqy">
<uri-param name="__ml_redirect__">/$1</uri-param>
</request>
<request uri="^/(.+)/act(\d+)" endpoint="/endpoint.xqy">
<uri-param name="play">$1.xml</uri-param>
<uri-param name="act" as="integer">$2</uri-param>
<param name="scene" as="integer" values="1|2|3" default="1"/>
</request>
<request uri="^/(.+)$" endpoint="/endpoint.xqy">
<uri-param name="play">$1.xml</uri-param>
</request>
<request uri="^/(.+)$" endpoint="/delete.xqy">
<http method="DELETE"/>
<param name="reason" required="true"/>
</request>
<request uri="^(.+)$" endpoint="/options.xqy" user-params="allow">
<uri-param name="__ml_options__">$1</uri-param>
<http method="OPTIONS"/>
</request>
</options>
let $uri := "/shakespeare/hamlet"
let $accept := xdmp:get-request-header("Accept")
let $params := map:map()
return rest:matching-request($options, ("uri","method"))
Now, I would have thought that the match would be:
<request uri="^/shakespeare/(.+)" endpoint="/redirect.xqy">
<uri-param name="__ml_redirect__">/$1</uri-param>
</request>
But, instead, the match is:
<request uri="^/(.+)$" endpoint="/endpoint.xqy">
<uri-param name="play">$1.xml</uri-param>
</request>
The reason that I'm asking is that I would like to come up with a rule for this expression, which is actually good regex: ^(\/openapi\/.+.yml)$
However, for 1) that regex is invalid according to MarkLogic, but ^(/openapi/.+.yml)$
is valid, and 2) if /shakespeare/hamlet
doesn't match ^/shakespeare/(.+)/(.+)
, then I don't understand what the regex is supposed to be that would match it.