Using regular expressions in Crystal formulas

Saturday 7 February 2015 @ 12:12 am

Regular expressions, for those of us who don’t see them often, are a group of symbols that allow you to efficiently define a complex string pattern. You can define this pattern with optional characters, varying lengths, and alternate spellings and punctuation. Below is a simple example showing how you would define the pattern found in a formatted height value using feet and inches:

^[0-9]+\'[ ]?([0-9]{1,2}[\"]?|)$

This says that the string must start with a digit. The digit must be followed by a single quote and then an optional space. The string must end with either 1 or 2 digits followed by an optional double quote.

Unfortunately, regular expressions are not a native feature of Crystal syntax. But Ido Millet of Millet software has just added several functions to the CUT Light DLL that make regular expressions available inside Crystal formulas. The functions allow you to test, search and replace strings based on the patterns defined using regular expressions. To read more about CUT Light as well as other DLLs that can add power to your Crystal formulas, you should read my article on User Defined Function Libraries (UFLs).

(For examples of my most popular formulas, please visit the FORMULAS page on my website.)







Leave a Reply

Recrystallize Pro