โ06-04-2024 04:35 PM - edited โ06-04-2024 04:38 PM
Hi guys,
I have a use case where I use regular expression to validate the input of postal code.
E.g. Formula = "95000-2707".match?(/(^\d{5}$)|(^\d{5}-\d{4}$)/) for matching the US postal codes.
However, this method won't work if the regular expression is stored in a lookup able.
E.g. "regular_expression" lookup table
country | regex |
United States | /(^\d{5}$)|(^\d{5}-\d{4}$)/ |
Formula = "95000-2707".match?(lookup("regular_expression", "country": "United States")["regex"])
I have also tried the following formula but no luck.
- "95000-2707".match?(lookup("regular_expression", "country": "United States")["regex"].to_s)
- "95000-2707".match?(/lookup("regular_expression", "country": "United States")["regex"]/) and "95000-2707".match?(/lookup("regular_expression", "country": "United States")["regex"].to_s/) with the following lookup table
country | regex |
United States | (^\d{5}$)|(^\d{5}-\d{4}$) |
Thank you
Solved! Go to Solution.
โ06-05-2024 10:23 AM
Thanks Gary.
I would like to share what I have found. Actually, removing the '/' at the beginning and end of the regex in formula syntax and lookup table works.
country | regex |
United States | (^\d{5}$)|(^\d{5}-\d{4}$) |
"95000-2707".match?(lookup("regular_expression", "country": "United States")["regex"])
Give it a shot
โ06-05-2024 10:26 AM
Well, that's a whole lot easier! You know, when I was working on the script, I also had to remove the '/' at the beginning and end to get it to work, but I didn't think to double back and check if that would work with Ruby! Glad it's all working now.