|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] RE using a variable within a regexp patternManuel Souto Pico m.soutopico at gmail.comFri Oct 2 00:39:34 PDT 2009
Dear David and Hans-Juergen, Thanks a lot for your replies and, notably, for Jans-Juergen's explanation. Very useful indeed! This is a bit more complex than perl's regular expressions but still quite straightforward at the end of the day. The solution had crossed my mind very fast, but then I got distracted and I forgot. But indeed this is what I needed: where $record/langSet[@xml:lang="en"]/tig/term[matches(., concat('^', $q, '.*$'))] Thanks a lot! And keep well :)) Chees, Manuel 2009/10/1 Hans-Juergen Rennau <http://x-query.com/mailman/listinfo/talk> > Hi Manual, > > if I understand you correctly, you wonder how you can compose a match > pattern from variable and fixed parts, e.g. framing a variable term by an > initial ^ and a trailing $, right? > > The solution is simple: use an _expression_ whose string value is the > desired sequence of characters. Often this will be achieved using the concat > function, whose arguments in turn may be literals, variable references, > function calls, path expressions.... Examples: > > matches(., concat('^', $q, '$')) > matches(., concat($prefix, $q, $postfix)) > matches(., concat('^', 'ID', position())) > matches(., concat('^', $n/@criterion, '.*s')) > > So the task becomes very simple if you remember that the way an expression > is resolved to a value is independent on the context where the value is > used. Therefore, you need not any special knowledge about the matches > function - all you need is the general understanding how to build an > expression that resolves to the intended string. > > With kind regards, > Hans-Juergen > > ------------------------------ > > Message: 4 > Date: Thu, 1 Oct 2009 20:53:29 +0200 > From: Manuel Souto Pico <http://x-query.com/mailman/listinfo/talk> > Subject: using a variable within a regexp pattern in > XQuery > To: http://x-query.com/mailman/listinfo/talk > Message-ID: > <http://x-query.com/mailman/listinfo/talk> > Content-Type: text/plain; charset="iso-8859-1" > > 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/20091001/728a81e2/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
|






