I was recently working on a customer project where I wanted to use regular expressions to do string comparison in Dynamics AX 2012. The customer wanted to identify the type of card and validate the card from the card number, based on the range of card numbers assigned to the card issuer. We can use regular expression to compare the card number with major providers and derive the type of card and validity of the card number.
Shortcomings in the #define Command
X++ provides several pre-compiler directives that we can use. The directives are processed before the resulting X++ code is given to the X++ compiler. These directives declare and handle macros and their values.
I decided to use the #define command, to store the constant value for regular expression for various card issuers in a macro. I ran into an existing shortcoming in the #define command. When we have closing brackets ‘)‘ in a macro value, Dynamics AX gives a compiler error with the description ‘Syntax error.’
The workaround for this is to use localMacro instead.
How to use Regular Expression in Dynamics AX
A regular expression is a pattern that the regular expression engine attempts to match in input text. Dynamics AX also provides extensive support for regular expression. Using Regular Expression in Dynamics AX is very simple, due to the ability to call .NET objects from AX.