Fluent Interface for Regular Expressions

Some years ago when we migrated Radeox – a wiki engine – to a new Regular Expression engine, we had to change lots of Regular Expressions. Today I would do it in a different way, with Fluent Interfaces. Joshua has a solution for building Regular expressions with a Fluent Interface, about which I wrote before.

Not only is this solution easier to understand than using a String for regular expressions, migrating from ORO Regex to JDK Regex for example would be easy with this solution. The solution we chose was to create two engine implementations for ORO and JDK regex: Compiler (JdkCompiler,OroCompiler), MatchResult (JdkMatchResult,OroMatchResult), Matcher (JdkMatcher,OroMatcher) and so on. For example:

The actual regular expressions are stored in Java .properties files, to make them easily exchangable. The bold expression looks like this for example:

With the migration of Radeox to a new regex implementation I had to write and implement several interfaces and it wasn’t very easy to both support ORO and the JDK implementation. It wan’t easy either to change the slightly different pattern dialact from ORO to JDK. With a Fluent Interface, just change the Fluent Interface, no need to think about different Java Regex APIs and to think about different syntaxes.

Thanks for listening.

Comments are closed.