|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] using a variable within a regexp pattern in XQueryManuel Souto Pico m.soutopico at gmail.comFri Oct 2 02:38:04 PDT 2009
Hi Michael,
Thanks a lot for your reply. Sorry about not being more explicit or clear.
I'll bear that in mind for my future emails.
What I meant with "works" is that the search expression and the term did
match. When they matched, the output was the term searched for. When they
didn't match, there was no output.
Thanks a lot for your suggestion. I certainly needed to use concat, but the
expression that eventually did the trick was:
matches(., concat('^', $q, '.*$'))
What I'd like is to control whether the search term matched the entire term,
part of it at the beginning, or part of it at the end, part of it in the
middle, etc.
Thanks again, and good night!
Manuel
2009/10/2 Michael Kay <http://x-query.com/mailman/listinfo/talk>
> It's very unhelpful to report that something "doesn't work" without
> saying how it failed. And if you expected the expression to do something
> useful, it's useful to say what you expected it to do: you can't expect us
> to guess the intention behind incorrect code.
>
> If $q is a variable containing part of a regular expression, then you can
> include it in a regex using the concat function:
>
> matches(., concat('(', $q, ')*')
>
>
> Regards,
>
> Michael Kay
> http://www.saxonica.com/
> http://twitter.com/michaelhkay
>
> ------------------------------
> *From:* http://x-query.com/mailman/listinfo/talk [mailto:http://x-query.com/mailman/listinfo/talk] *On
> Behalf Of *Manuel Souto Pico
> *Sent:* 01 October 2009 19:53
> *To:* http://x-query.com/mailman/listinfo/talk
> *Subject:* using a variable within a regexp pattern in
> XQuery
>
> Hi,
>
> I'm a bit stuck trying to run a regexp pattern in a XQuery search file.
>
> (1) where $record/langSet[@xml:lang="en"]/tig/term[matches(., $q)]
> works
> (2) where $record/langSet[@xml:lang="en"]/tig/term[matches(.,
> "$q")] doesn't work
> (3) where $record/langSet[@xml:lang="en"]/tig/term[matches(.,
> "^$q.*$")] doesn't work
> (4) where $record/langSet[@xml:lang="en"]/tig/term[matches(.,
> "^bu.+$")] works!
>
> Any ideas about how I can get to use regular expressions in this query?
>
> (4) retrieves 'bufer', 'bug' and 'bus'. If $q is 'bu', (1) retrieves as
> well 'attri*bu*te', 'contrast *bu*tton', etc.
>
> Thanks a lot!
>
> Cheers, Manuel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20091002/d6025020/attachment.htm
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






