The anchors mean that the expression must match the entirety of the input string, so “^re$” can only match the input string “re”.
If you want to match only the blank-delimited token “re” then you would want something like: “(^re\s|\sre\s|\sre$)” That is, match “re “ at start of input, “ re “ anywhere, or “ re” at end of input. Or you could tokenize the input and then use the equals operator: Tokenize(“I am learning regex”, “ “) = (“re”) Remember that the “=” operator is sequence comparison, so if any member of the left-hand sequence equals any member of the right-hand sequence, it resolves to true(). Cheers, Eliot ---- Eliot Kimber http://contrext.com On 10/13/17, 2:41 PM, "[email protected] on behalf of [email protected]" <[email protected] on behalf of [email protected]> wrote: Thanks for your reply But metacharacter addition not working it is behaving like , This statement is returning fn:matches("I am learning regex","^re$") false (expected) But this statement is returning fn:matches("I am learning re","^re$") false (unexpected) but I am expecting true for the same. -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Christopher Hamlin Sent: Friday, October 13, 2017 3:26 PM To: MarkLogic Developer Discussion <[email protected]> Subject: Re: [MarkLogic Dev General] exact match using regex You can use anchors, as fn:matches("I am learning regex","^re$") 7.6.2 fn:matches of https://www.w3.org/TR/xpath-functions/#flags says: Unless the metacharacters ^ and $ are used as anchors, the string is considered to match the pattern if any substring matches the pattern. But if anchors are used, the anchors must match the start/end of the string (in string mode), or the start/end of a line (in multiline mode). Note: This is different from the behavior of patterns in [XML Schema Part 2: Datatypes Second Edition], where regular expressions are implicitly anchored. On Fri, Oct 13, 2017 at 3:19 PM, <[email protected]> wrote: > Hi All, > > > > How to match exact word using fn:matches and regex. > > > > Example : fn:matches(“I am learning regex”,”re”) > > Above statement returning true as it is matching with “regex” but I > want it should match only when string found exact keyword. > > > > Regards, > > Vikas Singh > > > > This e-mail and any files transmitted with it are for the sole use of > the intended recipient(s) and may contain confidential and privileged > information. If you are not the intended recipient(s), please reply to > the sender and destroy all copies of the original message. Any > unauthorized review, use, disclosure, dissemination, forwarding, > printing or copying of this email, and/or any action taken in reliance > on the contents of this e-mail is strictly prohibited and may be > unlawful. Where permitted by applicable law, this e-mail and other > e-mail communications sent to and from Cognizant e-mail addresses may be monitored. > > _______________________________________________ > General mailing list > [email protected] > Manage your subscription at: > http://developer.marklogic.com/mailman/listinfo/general > _______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored. _______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
