manish payasi
manish payasi

Reputation: 87

regular expression to extract string value

I am getting the result as given below but i want to extract all file names individually through Xquery. So what will the best way to extract the files individually?

 db/Staff_Member1.xml db/Staff_Member2.xml db/Staff_Member3.xml db/Staff_Member4.xml db/Staff_Member5.xml db/Staff_Member6.xml db/Staff_Member7.xml db/Staff_Member8.xml db/Staff_Member9.xml db/Staff_Member10.xml db/Staff_Member11.xml db/Staff_Member12.xml db/Staff_Member13.xml db/Staff_Member14.xml db/Staff_Member15.xml

Upvotes: 0

Views: 160

Answers (2)

adamretter
adamretter

Reputation: 3517

If you want just the filename from a path, you could use

replace($your-string, ".*/(.*)", "$1")

This will work in XQuery 1.0 or 3.0

Upvotes: 2

Jens Erat
Jens Erat

Reputation: 38672

Given this is a sequence of strings returned by some XQuery, I'd go for tokenize on the path seperator / and further proceed the last segment. Run tokenize for each of the strings:

let $path := 'db/Staff_Member1.xml'
let $basename := tokenize($path, '/')[last()]
return $basename

A regular expression is not required and would just make things more complicated, and only work starting with XQuery 3.0, as XQuery 1.0 can verify if a string matches, not return matching substrings.

Upvotes: 2

Related Questions