ColdFusion Regular Expressions Tip

  • Post author:
  • Post category:Uncategorized

The other day I came across a situation where I wanted to use regular expression repetition syntax. I was trying to validate US currency, and I was dealing with the potential of commas for thousands separators. In my regular expression, at the start of the number (the left side) I wanted to allow 1 to 3 digits, followed by a comma. This is a perfect situation for regular expression repetition, which would look like this:^\d{1,3},So in that regex, the “{1,3}” says that we will allow from one to three digits. So any of these numbers would be valid:
345,643,196I looked in the CF docs and there is no mention of regular expression repetition! I was peeved that CF doesn’t support this, but I figured before I went too far looking for an alternative, I’d just try it to see if it works. Lo and behold, it works! So even though regex repetition is NOT in the CF docs, it IS supported. Good to know for future reference. đŸ™‚