Sorcerer's Tower

Java RegEx Utilities - v0.7 preview

Java RegEx Utilities, or jre-utils, is a CFC which provides a convenient way to access Java's regular expression functionality.

Whilst ColdFusion, Railo, and openBD are all built on Java, and CFML does have regular expression functions, they do not actually use the Java regular expression engine, which supports many useful regex constructs.

The purpose of jre-utils is to provide this extra power to CFML developers in a familiar and easy to use way.

I will shortly be releasing v0.7 of jre-utils, which adds a number of new functions, as well as making things more consistent, so I decided I would give this quick preview of what it contains.

With the addition of the rematch function to the latest CFML engines, I have added a match function to jre-utils. This is identical to the existing get function, but the argument order is swapped to be consistent with rematch.
This same aliasing has been done with other related functions, as seen below.

get / match - returns an array of strings for all the matches found.

getFirst / matchFirst - returns the first match found as string, this is more efficient than doing get(...)[1] since it stops as soon as matching once.

getGroups / matchGroups - returns an array of structs for all the matches found. Each struct contains the full match, plus an array of backreference group matches.

matches - returns true if regex matches string, false otherwise.

split - converts a string to an array, by splitting at the specified regex.

I will be providing full documentation and usage examples for each of these functions with the final release, but for those of you eager to get at the latest version before then, you can download jre-utils v0.7-dev already.


So far, this code has only been run against the following engines:

Feedback on other CFML engines is very much appreciated, and please feel free to leave any general comments or questions you might have.