Mailing List Archive

Regular Expressions in Conditionals
Hello,
 
I'm fairly new to working with Interchange and am running into a syntax issue.
 
The problem I am trying to solve is deciphering between tracking numbers from two different shipping companies, and displaying a different message depending on which company the tracking number belongs to. Each company has its own set of rules for how the tracking number is structured, so its fairly straightforward to use a regular expression in order to pick apart the number.
 
I am using the "if" ITL Tag in order to check the variable against the regular expression, but I am running into a comparison issue. The line is "[if tracking_number =~ /^[0-9]{12}$/]" and it should return true if the characters are between 0-9 and the number is 12 digits long. Is it possible to compare a variable to a regular expression in the "if" tag? If so, am I doing the regular expression comparison incorrectly? 
 
Best,
Mihai Dan
Air Delights
mihai@airdelights.com

_______________________________________________
interchange-users mailing list
interchange-users@interchangecommerce.org
https://www.interchangecommerce.org/mailman/listinfo/interchange-users
Re: Regular Expressions in Conditionals [ In reply to ]
> On Sep 28, 2020, at 4:33 PM, mihai@airdelights.com wrote:
>
> Hello,
>
> I'm fairly new to working with Interchange and am running into a syntax issue.
>
> The problem I am trying to solve is deciphering between tracking numbers from two different shipping companies, and displaying a different message depending on which company the tracking number belongs to. Each company has its own set of rules for how the tracking number is structured, so its fairly straightforward to use a regular expression in order to pick apart the number.
>
> I am using the "if" ITL Tag in order to check the variable against the regular expression, but I am running into a comparison issue. The line is "[if tracking_number =~ /^[0-9]{12}$/]" and it should return true if the characters are between 0-9 and the number is 12 digits long. Is it possible to compare a variable to a regular expression in the "if" tag? If so, am I doing the regular expression comparison incorrectly?

Hi Mihai,

I suspect you’re just needing to specify *which* variable is getting compared against; try `[if scratch tracking_number =~ /…/]` to test the scratch variable in question.

HTH,

David