Using full Java regular expressions

Saturday, 13 October 2012 · 8 messages · last reply 21 Oct 2012
TT
The Trainspotter13 Oct 2012 16:10 #
Hi, I'm currently converting my project to use BaseX instead of Saxon. One thing you can do in Saxon is provide a flag (an exclamation mark) to your regular expression to tell the matches function to use the Java regular expression processor, rather than the rather cut down expressions available in the XQuery spec. Is there anything similar in BaseX? If not what do you recommend to define a Java regular expression based function for XQuery? Thanks in advance, Gary
MS
Michael Seiferle15 Oct 2012 09:58 #
Hi Gary, not directly a flag, but you are for sure able to use Java classes from within BaseX like so https://gist.github.com/c72fad2758af668eb0f1 More information on our Java Bindings can be found here: http://docs.basex.org/wiki/Java_Bindings I hope this helps, feel free to ask for more help =) Michael
Quoted text · The Trainspotter · 15 lines
Am 13.10.2012 um 16:10 schrieb The Trainspotter <wys01 at btinternet.com>: > Hi, > > I'm currently converting my project to use BaseX instead of Saxon. One thing you can do in Saxon is provide a flag (an exclamation mark) to your regular expression to tell the matches function to use the Java regular expression processor, rather than the rather cut down expressions available in the XQuery spec. > > Is there anything similar in BaseX? > > If not what do you recommend to define a Java regular expression based function for XQuery? > > Thanks in advance, > Gary > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
TT
The Trainspotter15 Oct 2012 15:35 #
Hi, Yes, this helps. I did go down a similar route with saxon before I found the exclamation mark flag. The issue I had was that using the Java bindings in Saxon was very inefficient when calculating matches for large number of attributes. This may have been my fault for not compiling the regex outside of the "for" statement, but I remember being relieved to find the magic flag to switch to Java regular expressions. I'll try out the github reference and see how I get on. Is this switch something I could request as an enhancement, if so could I expect it to be implemented any time soon? Thanks for you help, Gary ________________________________ From: Michael Seiferle <ms at basex.org> To: The Trainspotter <wys01 at btinternet.com> Cc: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Sent: Monday, 15 October 2012, 8:58 Subject: Re: [basex-talk] Using full Java regular expressions Hi Gary, not directly a flag, but you are for sure able to use Java classes from within BaseX like so https://gist.github.com/c72fad2758af668eb0f1 More information on our Java Bindings can be found here: http://docs.basex.org/wiki/Java_Bindings I hope this helps, feel free to ask for more help =) Michael
Quoted text · Michael Seiferle · 1 line
Am 13.10.2012 um 16:10 schrieb The Trainspotter <wys01 at btinternet.com>:
Hi,
Quoted text · Michael Seiferle · 17 lines
> > >I'm currently converting my project to use BaseX instead of Saxon. One thing you can do in Saxon is provide a flag (an exclamation mark) to your regular expression to tell the matches function to use the Java regular expression processor, rather than the rather cut down expressions available in the XQuery spec. > > >Is there anything similar in BaseX? > > >If not what do you recommend to define a Java regular expression based function for XQuery? > > >Thanks in advance, >Gary_______________________________________________ >BaseX-Talk mailing list >BaseX-Talk at mailman.uni-konstanz.de >https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
MS
Michael Seiferle15 Oct 2012 18:14 #
Quoted text · The Trainspotter · 5 lines
Am 15.10.2012 um 15:35 schrieb The Trainspotter <wys01 at btinternet.com>: > Is this switch something I could request as an enhancement, Yes > if so could I expect it to be implemented any time soon? >
...not necessarily as I can not promise that someone will jump on this train anytime soon. BUT it is for sure the first step towards completion :-)) Hope this helps Michael
CG
Christian Grünin reply to The Trainspotter, 13 Oct 2012, 16:1021 Oct 2012 19:23 #
Hi Gary, BaseX provides the full XQuery 3.0 regular expression syntax [1,2]; maybe it already contains the features you need for your queries? If not, could you give us a hint which ones you are missing? While we could add an additional flag to the regex evaluator in BaseX, we are generally hesitant to do so, because it would be yet another vendor (i.e., Saxon and BaseX)-specific extension. Best, Christian [1] http://www.w3.org/TR/xpath-functions-30/#regex-syntax [2] http://www.w3.org/TR/xmlschema-2/#regexs
Quoted text · The Trainspotter · 19 lines
> I'm currently converting my project to use BaseX instead of Saxon. One thing > you can do in Saxon is provide a flag (an exclamation mark) to your regular > expression to tell the matches function to use the Java regular expression > processor, rather than the rather cut down expressions available in the > XQuery spec. > > Is there anything similar in BaseX? > > If not what do you recommend to define a Java regular expression based > function for XQuery? > > Thanks in advance, > Gary > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
TT
The Trainspotter21 Oct 2012 19:35 #
Hi Christian, The regular expression capability I was missing was the word boundary \b matching. I followed the Java bindings example so I can now use the Java String.matches() function which allows me to use the \b match (and others too) which are not part of the standard regex capability. This performs very well, so I think you can hold off adding another extension. Cheers, Gary ________________________________ From: Christian Grün <christian.gruen at gmail.com> To: The Trainspotter <wys01 at btinternet.com> Cc: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Sent: Sunday, 21 October 2012, 18:23 Subject: Re: [basex-talk] Using full Java regular expressions Hi Gary, BaseX provides the full XQuery 3.0 regular expression syntax [1,2]; maybe it already contains the features you need for your queries? If not, could you give us a hint which ones you are missing? While we could add an additional flag to the regex evaluator in BaseX, we are generally hesitant to do so, because it would be yet another vendor (i.e., Saxon and BaseX)-specific extension. Best, Christian [1] http://www.w3.org/TR/xpath-functions-30/#regex-syntax [2] http://www.w3.org/TR/xmlschema-2/#regexs
Quoted text · Christian Grün · 19 lines
> I'm currently converting my project to use BaseX instead of Saxon. One thing > you can do in Saxon is provide a flag (an exclamation mark) to your regular > expression to tell the matches function to use the Java regular expression > processor, rather than the rather cut down expressions available in the > XQuery spec. > > Is there anything similar in BaseX? > > If not what do you recommend to define a Java regular expression based > function for XQuery? > > Thanks in advance, > Gary > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
JE
Jens Erat21 Oct 2012 19:50 #
Hi Gary, word boundaries are nothing but sugar to regex expressions for engines supporting lookahead and -behind. They're defined by [1] as all positions
Quoted text · The Trainspotter · 3 lines
> - Before the first character in the string, if the first character is a word character. > - After the last character in the string, if the last character is a word character. > - Between two characters in the string, where one is a word character and the other is not a word character.
This can easily be written as ((?<=\w)(?!\w)|(?<!\w)(?=\w)) which actually describes the third rule, but $ and ^ are "non-word-characters" anyway. Using non-XQuery-functions (as calling Java from XQuery) will prevent future (hopefully soon) performance optimizations regarding parallel execution, better stick to the XQuery's default regex whenever possible. Kind regards from Lake Constance, Germany, Jens Erat [1]: http://www.regular-expressions.info/wordboundaries.html
-- Jens Erat [phone]: tel:+49-151-56961126 [mail]: mailto:email at jenserat.de [jabber]: xmpp:jabber at jenserat.de [web]: http://www.jenserat.de PGP: 350E D9B6 9ADC 2DED F5F2 8549 CBC2 613C D745 722B
Quoted text · The Trainspotter · 56 lines
Am 21.10.2012 um 19:35 schrieb The Trainspotter <wys01 at btinternet.com>: > Hi Christian, > > The regular expression capability I was missing was the word boundary \b matching. I followed the Java bindings example so I can now use the Java String.matches() function which allows me to use the \b match (and others too) which are not part of the standard regex capability. This performs very well, so I think you can hold off adding another extension. > > Cheers, > Gary > > From: Christian Grün <christian.gruen at gmail.com> > To: The Trainspotter <wys01 at btinternet.com> > Cc: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> > Sent: Sunday, 21 October 2012, 18:23 > Subject: Re: [basex-talk] Using full Java regular expressions > > Hi Gary, > > BaseX provides the full XQuery 3.0 regular expression syntax [1,2]; > maybe it already contains the features you need for your queries? If > not, could you give us a hint which ones you are missing? > > While we could add an additional flag to the regex evaluator in BaseX, > we are generally hesitant to do so, because it would be yet another > vendor (i.e., Saxon and BaseX)-specific extension. > > Best, > Christian > > [1] http://www.w3.org/TR/xpath-functions-30/#regex-syntax > [2] http://www.w3.org/TR/xmlschema-2/#regexs > ___________________________ > > > I'm currently converting my project to use BaseX instead of Saxon. One thing > > you can do in Saxon is provide a flag (an exclamation mark) to your regular > > expression to tell the matches function to use the Java regular expression > > processor, rather than the rather cut down expressions available in the > > XQuery spec. > > > > Is there anything similar in BaseX? > > > > If not what do you recommend to define a Java regular expression based > > function for XQuery? > > > > Thanks in advance, > > Gary > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
CG
Christian Grünin reply to The Trainspotter, 21 Oct 2012, 19:3521 Oct 2012 20:50 #
Quoted text · The Trainspotter · 5 lines
> The regular expression capability I was missing was the word boundary \b > matching. I followed the Java bindings example so I can now use the Java > String.matches() function which allows me to use the \b match (and others > too) which are not part of the standard regex capability. This performs very > well, so I think you can hold off adding another extension.
Sounds fine. By the way, if you wish \b to be included in a future version of XQuery, you are invited to post a feature request on the W3 Bugzilla list [1]. [1] https://www.w3.org/Bugs/Public/query.cgi
Quoted text · The Trainspotter · 50 lines
> ________________________________ > From: Christian Grün <christian.gruen at gmail.com> > > To: The Trainspotter <wys01 at btinternet.com> > Cc: "basex-talk at mailman.uni-konstanz.de" > <basex-talk at mailman.uni-konstanz.de> > Sent: Sunday, 21 October 2012, 18:23 > > Subject: Re: [basex-talk] Using full Java regular expressions > > Hi Gary, > > BaseX provides the full XQuery 3.0 regular expression syntax [1,2]; > maybe it already contains the features you need for your queries? If > not, could you give us a hint which ones you are missing? > > While we could add an additional flag to the regex evaluator in BaseX, > we are generally hesitant to do so, because it would be yet another > vendor (i.e., Saxon and BaseX)-specific extension. > > Best, > Christian > > [1] http://www.w3.org/TR/xpath-functions-30/#regex-syntax > [2] http://www.w3.org/TR/xmlschema-2/#regexs > ___________________________ > >> I'm currently converting my project to use BaseX instead of Saxon. One >> thing >> you can do in Saxon is provide a flag (an exclamation mark) to your >> regular >> expression to tell the matches function to use the Java regular expression >> processor, rather than the rather cut down expressions available in the >> XQuery spec. >> >> Is there anything similar in BaseX? >> >> If not what do you recommend to define a Java regular expression based >> function for XQuery? >> >> Thanks in advance, >> Gary >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > >

⚡Generated with XQuery