Home
Regular ExpressionsRegular Expressions
Version 0.6 introduces support for a regexp function that allows a regular expression to be applied to a string and a boolean result returned. However JoSQL has NO native support for regular expressions, instead of arbitrarily selecting an implementation the decision was made to support ALL implementations and leave it to the developer to select the implementation that they prefer and use that. Also, selecting a particular implementation would also vastly increase the size of the download which is undesirable (not to mention potential licensing conflicts since most are LGPL/GPL and JoSQL uses an Apache license).

JoSQL does have support for a number of the "standard implementations" if they are available in the CLASSPATH. The supported implementations are (in no particular order):

NameSupported VersionJoSQL Instance Name
External site, opens in new window ORO2.0.8oro
External site, opens in new window Java (java.util.regex)1.4+java
External site, opens in new window Apache RegExp1.3apache.regexp
External site, opens in new window GNU RegExp1.1.4gnu
The "default" implementation that is used (unless one is selected explicitly) is: java. Please note that the JoSQL Instance Name is an arbitrary name assigned to each of the regular expression implementation library so that they can be identified easily, they are NOT related to any name provided by the library itself. It should also be noted that the versions provided here are those that are known to work with JoSQL.

Two functions are provided to allow developers access to the regular expression functionality: regexp (Object, String) and regexp (Object, String, String). The first function uses the "default" implementation, if that implementation is not available (you are using a Java version less than 1.4) then JoSQL will look for any of the other "standard" implementations, if none of them are available then an exception will be thrown by the function indicating that the library isn't available. The second function allows the developer to specify the implementation to use by using one of the JoSQL Instance Name strings defined in the table above.

For example:
/* Use the default regular expression library. */
SELECT *
FROM   java.lang.Object
WHERE  regexp (class.name, 'java.*Object')

/* Use a named regular expression library */
SELECT *
FROM   java.lang.Object
WHERE  regexp (class.name, 'java.*Object', 'gnu')

/* You can even used different regular expression libraries for different calls
   to "regexp"! */
SELECT *
FROM   java.lang.Object
WHERE  regexp (class.name, 'java.*Object', 'gnu')
AND    regexp (class.name, 'java.*Object', 'java')
AND    regexp (class.name, 'java.*Object', 'oro')
To make your preferred library available for use by JoSQL simply add the relevant jar file to your CLASSPATH, it's that easy!
Specifying the default implementation
It is possible to override the default implementation that should be used. For example if you always use the ORO implementation, this is done by calling:
setDefaultInstanceName(java.lang.String)The instance must already be installed and available.
Installing New Implementations
If you have a different regular expression implementation that you would like the regexp functions to use, you can either create your own function that provides the relevant access, or install a new implementation in the JoSQL regular expression factory by calling:
addInstance(java.lang.String, org.josql.functions.regexp.RegExp, boolean)This will then map the implementation of the org.josql.functions.regexp.RegExp interface against the name provided by the String parm. The boolean indicates, when set to true, that the instance should be the default.
See Also