Just noticed that my data pipeline is receiving malformed phone numbers from the Architect flow. I am pulling analytics data via the Python SDK, but the source data in the CRM is getting corrupted by a bad formatting logic in the flow.
I need an Architect expression to transform a raw E.164 string (e.g., +1XXXXXXXXXX) into a standard US format (XXX) XXX-XXXX. I assumed I could use the regexreplace function, but it seems to be choking on the plus sign or the length validation.
Here is my current attempt in the Set Data Action:
regexreplace(${interaction.contact.phone.number}, "^\\+1([0-9]{3})([0-9]{3})([0-9]{4})$", "(\\1) \\2-\\3")
The result is often empty or just the original string. I am testing this in the Expression Builder, but the preview does not show intermediate steps.
- I confirmed the input string is exactly 12 characters including the
+. - I tried escaping the
+as\\+and\+. - I tried using
substringto chop the first two chars, but that feels brittle if the country code varies.
The Analytics API downstream expects the specific (XXX) XXX-XXXX format for grouping. If the format fails, the aggregation breaks, and I have to write a messy pandas fix in the ETL script. I want to fix this at the source.
Is regexreplace the right tool here? Or should I be using a snippet? The documentation is sparse on regex syntax support in Architect. I am seeing no error logs, just silent failure.
How do I correctly write an Architect expression to format +1XXXXXXXXXX to (XXX) XXX-XXXX using regexreplace or a more robust string manipulation method?