CXone Architect Expression for Phone Number Formatting

I’m trying to format a raw phone number string coming from an external API into a standard US format like (XXX) XXX-XXXX. The input is always in the E.164 format, for example +15551234567.

I’ve tried using the substring function in the Architect Data Action expression, but the logic is getting messy. The expression builder doesn’t seem to support standard regex replace, so I’m stuck chaining multiple substring calls.

Here is what I have so far:

concat(
 "(",
 substring(${contact.phone}, 2, 3),
 ") ",
 substring(${contact.phone}, 5, 3),
 "-",
 substring(${contact.phone}, 8, 4)
)

This works for the 11-character strings, but if the source sometimes sends the number without the country code (just 10 digits), the indices are off. I’d rather have a single expression that handles both cases or strips the leading +1 automatically.

Is there a cleaner way to do this in the Architect expression language without writing a custom ? Or should I just bite the bullet and write a script to handle the normalization before it hits the Architect flow?