Could someone explain why my current regex fails in the Architect expression editor when converting E.164 numbers? I am trying to transform a string like +14155552671 into (415) 555-2671 using the built-in functions. The documentation states: “The replace function allows you to substitute a substring with another value.” I assumed I could use nested replace calls or a simple regex, but the parser rejects complex lookaheads.
I have tried using replace(replace($data.PhoneNumber, "^+1", ""), "(\d{3})(\d{3})(\d{4})", "($1) $2-$3"). This results in a validation error during the flow deployment phase. The error message is generic, stating that the expression is invalid. I expected the capture groups (\d{3}) to work similarly to Python re module groups, but Architect seems to use a different regex flavor.
My FastAPI backend receives the raw E.164 string from the webhook payload. I need to format this within the Architect flow before passing it to an IVR prompt. Can you provide a working expression snippet that handles the +1 prefix removal and the subsequent formatting? I need to ensure the output matches exactly (XXX) XXX-XXXX for compliance with our legacy PBX integration requirements.