Sunny
Sunny

Reputation: 2154

Marklogic:How to Search documents with regex?

I have recently started working on MarkLogic 10 Database

What I need to do is find the documents who have id like

wew35r-ui856-iiu

When I query like this

cts:element-value-match(xs:Qname("id"),".*\-.*")

I get 0 results

but when I do

fn:matches("wew35r-ui856-iiu",".*\-.*")
It return true

And surprisingly when I do

cts:element-value-match(xs:Qname("id"),"*")

I get whole list which includes wew35r-ui856-iiu as well.

I had looked into the documentation and all but was not able to make it work.

Upvotes: 1

Views: 440

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66781

Full regex patterns are not supported for cts:element-value-match, only wildcard patterns.

To use a wildcard pattern to look for values that contain a dash -:

cts:element-value-match(xs:QName("id"),"*-*")

And then if you needed, you could filter those results with a more specific regex in a predicate filter:

cts:element-value-match(xs:QName("id"),"*-*")[matches(., "(\w+-\w+){2}")]

Upvotes: 3

Related Questions