Architect expression to format phone number +1XXXXXXXXXX to (XXX) XXX-XXXX

Quick question about architect expressions. i am trying to format a phone number from +1XXXXXXXXXX to (XXX) XXX-XXXX in a data action. i have tried using replace and substring but it feels messy. is there a cleaner way to do this with regex or built-in functions? here is what i have so far: replace(replace(replace(phone, '+1', ''), '-', ''), ' ', '') but i need to add the parentheses and dashes. any help would be great.

You should probably look at at the regex_replace function. It is significantly cleaner than chaining multiple replace calls. The pattern below extracts the area code and the remaining seven digits, then reformats them directly.

regex_replace(phone, "^\\+1?(\\d{3})(\\d{3})(\\d{4})$", "($1) $2-$3")

This assumes phone is already stripped of non-digit characters except the leading +1. If your source data is messy, sanitize it first:

regex_replace(
 regex_replace(phone, "[^0-9+]", ""), 
 "^\\+1?(\\d{3})(\\d{3})(\\d{4})$", 
 "($1) $2-$3"
)

In Terraform, I would handle this logic in the deployment scripts or a Lambda, not in Architect. Hardcoding formatting in flows creates technical debt. If the number format changes, you break every flow using that expression. Keep Architect logic for routing, not data transformation. Use for_each in your modules to push standardized formatting rules to your contact center data actions if you must do it at scale. But regex is the only way to do it cleanly in the UI.

This looks like a solid approach.

is there a cleaner way to do this with regex or built-in functions?

The regex_replace solution above is definitely the cleanest. Just ensure your input variable is strictly digits after the country code. If you’re pulling from an external API via my Node.js middleware, I’d sanitize it before passing it to Architect to avoid null returns.