[xquery-talk] Regular Expression search

Michael Kay mhk at mhk.me.uk
Thu Dec 15 00:08:30 PST 2005


Use
 
//*[matches(., "Name")]
 
But of course this could be done equally well using the simpler contains()
function. The matches() function comes into its own with a more complex
expression such as
 
//*[matches(., "^(My|Your) Name")]
 
which requires the string to start with "My Name" or "Your Name".
 
Of course //* would be better replaced by a more specific expression. In
fact you want to be careful with this because with a schema-aware query, the
above expression could give you a type error: it will fail when you apply
the predicate to an element that has element-only content.
 
I have a feeling you might be asking "how do I write regular expressions".
There are a few tutorials around - try for example
http://www.zvon.org/other/PerlTutorial/Output/ There are a few differences
between regular expressions in say Perl or Python and regular expressions in
XPath 2.0, but you can get through the first 20 or so examples in this
tutorial before you hit them.
 
Michael Kay
http://www.saxonica.com/


  _____  

From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On Behalf Of
Elarrat, EFC
Sent: 14 December 2005 18:24
To: talk at xquery.com
Subject: Re: [xquery-talk] Regular Expression search


Me again...just trying to know the following:
 
<tagA>
    <subTagA>My Name Is Eduardo</subTagA>
</tagA>
<tagB>
    <subTagB>My Name Is Elarrat</subTagB> //Corrected! =)
</tagB>
 
I saw the matches function and I got it well (I think...), but could anybody
please give me an example of how to use the matches function on this case?
like, searching for all tags that contains "Name"? Like "Name*" or "*Name"? 
 
If somebody doesn't understand, please ask Howard to translate it for you =)
 
Thanks a lot
 
Eduardo Elarrat

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xquery.com/pipermail/talk/attachments/20051215/8b0d4ac6/attachment.htm


More information about the talk mailing list