Architect expression regex for +1XXXXXXXXXX to (XXX) XXX-XXXX failing on leading plus

I’m trying to normalize inbound caller IDs in an Architect Data Action before passing them to a downstream REST API that expects a strict (XXX) XXX-XXXX format. The incoming value from the conversation object is consistently coming through as +1XXXXXXXXXX (E.164 with country code).

I’ve tried a few variations of the replace function combined with substrings, but the regex engine in Architect seems finicky with the leading + and the country code length. My current attempt looks like this:

replace(replace(${interaction.call.from.phone_number}, "\+1", ""), "(\\d{3})(\\d{3})(\\d{4})", "($1) $2-$3")

The issue is that the first replace isn’t stripping the +1 reliably when there are spaces or when the country code is missing (though that’s rare in our US-only setup). Also, if the input is already formatted differently, the regex captures fail silently or return the original string.

I’ve checked the Event delivery logs and the payload schema validation, so I know the data is arriving intact. The problem is purely in the transformation logic within the Data Action JSON.

Is there a more solid way to handle the country code stripping and formatting in one go? Or am I better off using a series of if statements to check the length and prefix before applying the regex? The replace function doesn’t seem to support non-capturing groups or lookaheads, which makes this a bit of a pain.

Here’s the JSON snippet for the data action step:

{
 "name": "NormalizePhone",
 "type": "data_action",
 "inputs": {
 "phoneNumber": "${interaction.call.from.phone_number}"
 },
 "outputs": {
 "formattedNumber": "replace(replace(${inputs.phoneNumber}, \"\\+1\", \"\"), \"(\\\\d{3})(\\\\d{3})(\\\\d{4})\", \"($1) $2-$3\")"
 }
}