Architect Expression: Regex for +1XXXXXXXXXX to (XXX) XXX-XXXX

We’re trying to normalize phone numbers in an Architect Data Action before sending them to our tracing endpoint. The source data comes in as E.164 format like +15551234567, and we need it formatted as (555) 123-4567 for the downstream API contract.

I’ve tried using the standard replaceAll function with regex, but Architect expressions are finicky with capture groups and escaping. Here’s the current expression that’s failing:

replaceAll(contact.phoneNumber, "\\+1(\\d{3})(\\d{3})(\\d{4})", "($1) $2-$3")

The issue is that replaceAll in Architect doesn’t seem to support backreference capture groups like $1 or $2. It treats them as literal strings, so the output is literally ($1) $2-$3 instead of the formatted number.

I also tried chaining substring calls:

concat("(", substring(contact.phoneNumber, 2, 3), ") ", substring(contact.phoneNumber, 5, 3), "-", substring(contact.phoneNumber, 8, 4))

This works for the +1 prefix, but it breaks if the number comes in without the country code (e.g., 5551234567) or with a different prefix. We need a solid way to handle just the +1 case specifically, or fail gracefully.

Is there a supported regex engine in Architect that handles capture groups, or do I need to write a custom JavaScript snippet in a Studio flow to do this formatting before the Data Action runs? We’d prefer to keep it in the Data Action config for visibility in our OTel traces, but the expression language feels limited for string manipulation.

Any examples of successful phone number formatting in Architect expressions would be appreciated. We’re running on the latest US1 environment.