Architect expression to format E.164 phone number to US standard

I’m building an integration that requires passing a formatted phone number to an external webhook. The incoming data from Genesys Cloud is in E.164 format, like +15551234567. I need to convert this to (555) 123-4567 within an Architect flow before the HTTP request fires.

I’ve tried using standard string manipulation functions, but Architect expressions are limited. I attempted something like:

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

This fails because the regex engine in Architect doesn’t support capture groups or the replace method with regex callbacks like JavaScript does. It just treats the pattern as a literal string.

Is there a built-in function or a workaround using split and join or substring indexing to achieve this? I can’t use a studio snippet here because this is a pure Architect flow. I need a reliable expression that handles the country code stripping and the parenthesis/dash formatting. Any ideas on how to construct this without external scripting?