ABRegExBuilder: Human readable RegEx

ABRegExBuilder is a class to build RegEx patterns in a human readable way. It’s the Xojo translation of RegExpBuilder written by Andrew Jones. It should be noted that this isn’t aiming to replace traditional regular expressions completely, but it may provide a tool for those who have difficulty writing them to have access to a more “human-readable” version of the expressions.

If you know you way around working with regular expressions, it’ll likely take up more of your time than necessary. This is geared towards those that aren’t fond of working with traditional regular expressions (guilty) and want to have a method for writing and using them in a very generic and human-readable way. It would be a great tool to use for improving maintainability within large scale projects that relied heavily on the use of expressions so that developers wouldn’t have to go “what the hell does this gibberish do?”.

ex:

Builder = new ABRegExBuilder
Call Builder. _
      StartOfLine. _ ' start
      ThenString("$"). _ ' a dollar sign
      Some(""). _ ' some
      Digits. _ ' digits
      ThenString("."). _ 'followed by a point
      Exactly(2). _ ' only two
      Digits. _ ' digits
      EndOfLine ' at the end
' generates: (?:^)(?:(?:\\$){1,1})(?:(?:(?:(?:\\d){1,1})){1,})(?:(?:\\.){1,1})(?:(?:(?:(?:\\d){1,1})){2,2})(?:$)
Dim bool as Boolean 
bool = Builder.ABREBMatches("$123.45") // returns true
bool = Builder.ABREBMatches("$123.456") // returns false
bool = Builder.ABREBMatches("123.45") // returns false

More examples are in the project file.
Download: http://gorgeousapps.com/RegExBuilder.zip

Obviously, due to the nature of the beast, these expressions aren’t optimized by any means as this class clearly focuses on improving readability over performance.

It is free so use/add/modify whatever you want. I’m sure a guru like @Kem Tekinay could do wonders to optimize it :slight_smile:

Nice idea.