It's something to do with the '?' making the preceding text optional.
replace("/search?q=test", "^/search\?q=", "/v1/search?options=appl&q=")
=>
/v1/search?options=appl&q=test
-- Mike
On 30 Jul 2013, at 11:36 , "Dunlap, Zachariah" <[email protected]> wrote:
> I gave that a shot and it didn’t work either. Here’s what I tried in
> QConsole:
>
> xquery version "1.0-ml";
>
> let $url := "/search?q=test"
>
> return fn:replace($url, "/search?q=", "/v1/search?options=appl&q=")
>
> Can you spot anything else I might be doing wrong?
>
> Thanks for your reply,
>
> Zach
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Will Thompson
> Sent: Tuesday, July 30, 2013 2:34 PM
> To: MarkLogic Developer Discussion
> Subject: Re: [MarkLogic Dev General] fn:replace in QConsole
>
> Carrot and dollar are beginning of string/end of string anchors. So the
> expression "^/search?q=$" will only match if there is no text preceding or
> following "/search?q=". If you want to allow text to match following the
> expression, then remove the dollar anchor: "^/search?q=". Then it can match
> strings like "/search?q=my querystring".
>
> -Will
>
> From: <Dunlap>, Zachariah <[email protected]>
> Reply-To: MarkLogic Discussion <[email protected]>
> Date: Tuesday, July 30, 2013 11:29 AM
> To: MarkLogic Discussion <[email protected]>
> Subject: [MarkLogic Dev General] fn:replace in QConsole
>
> I’m trying to test using fn:replace in QConsole and I’m hitting a small snag
> but can’t figure out where I’m going wrong.
>
> When I run this query in QConsole:
>
> xquery version "1.0-ml";
>
> let $url := "/search?q=test"
> return fn:replace($url, "^/search?q=$", "/v1/search?options=appl&q=")
>
> I get back the string in $url and not the replacement, I can’t tell what I’m
> doing wrong.
>
> I’m using this query in the url rewrite section of one of our app servers
> and it works great:
>
> xquery version "1.0-ml";
>
> let $url := xdmp:get-request-url()
> return fn:replace($url, "^/search$", "/login.xqy"
>
> This leaves me a bit stumped. Any help would be greatly appreciated.
>
> Thanks,
>
> Zach
>
> The information contained in this communication is intended for the use
> of the designated recipients named above. If the reader of this
> communication is not the intended recipient, you are hereby notified
> that you have received this communication in error, and that any review,
> dissemination, distribution or copying of this communication is strictly
> prohibited. If you have received this communication in error, please
> notify The Associated Press immediately by telephone at +1-212-621-1898
> and delete this email. Thank you.
> [IP_US_DISC]
>
>
> msk dccc60c6d2c3a6438f0cf467d9a4938
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general