Architect expression for phone number formatting: regex replace not working

Trying to format a phone number coming in as +1XXXXXXXXXX to (XXX) XXX-XXXX in an Architect Data Action.

Used this expression:

Replace(PhoneNumber, "^\+1(\d{3})(\d{3})(\d{4})$", "($1) $2-$3")

The result is always just the original string. No errors, just no change. The input is definitely +15551234567.

Checked the regex in an online tester and it works fine. Is there something weird with how Architect handles backreferences or escape characters? Or is Replace not doing a full regex match?

Tried Trim first to be safe but that didn’t help. Need this for a downstream API call that is strict about format.

The issue is likely the anchors. Architect’s regex engine doesn’t always play nice with ^ and $ inside Replace when dealing with raw strings. It’s safer to just match the pattern without anchoring the start and end explicitly, or ensure the input is clean.

Try dropping the anchors. It usually fixes the phantom matches.

Replace(PhoneNumber, "\\+1(\\d{3})(\\d{3})(\\d{4})", "($1) $2-$3")

Also, double-check that PhoneNumber isn’t a string object with hidden whitespace. Sometimes the API returns " +15551234567" (note the space). If that’s the case, wrap it in Trim() first.

Replace(Trim(PhoneNumber), "\\+1(\\d{3})(\\d{3})(\\d{4})", "($1) $2-$3")

If that still returns the original string, your input might not actually match the digit count. Check the debug logs. The variable might be coming in as 15551234567 (no plus sign) or with extra digits.