Docs state: “Use the replace function to substitute characters in a string based on a regular expression.”
I’m trying to format a phone number coming into the flow from +1XXXXXXXXXX to (XXX) XXX-XXXX. The source data is clean, just E.164 format. I need this formatted for a downstream SMS provider that rejects raw E.164.
Here is the expression I’ve built in the Set Value block:
replace(toString(contact.phoneNumber), "^(\+1)(\d{3})(\d{3})(\d{4})$", "($2) $3-$4")
The logic seems sound. The regex captures the country code, area code, prefix, and line number. The replacement string maps them to the desired format. However, the output variable is always empty. It’s not throwing an error, just returning a blank string.
I’ve verified the input variable contact.phoneNumber is not null. I even added a simple toString() wrapper just in case the type was weird, but that didn’t help.
Docs also mention: “Regular expressions in Architect expressions follow standard Java regex syntax.”
I tested this exact regex in an online Java regex tester and it works perfectly. The capture groups match. The replacement works. So why is Architect choking on it?
I tried stripping the +1 first with another replace, then formatting the rest. Same result. Empty string.
Is there a limitation on the replace function in Architect? Or maybe the regex engine is stricter than standard Java? I’ve seen issues with escaping before, but I’ve tried \\d and \d and both fail.
Here is the JSON payload from the initial trigger:
{
"phoneNumber": "+15551234567",
"contactId": "98765"
}
The value is definitely there. I’ve logged the raw value and it’s correct. Just the formatted version is missing.
Any ideas? I’m stuck. This should be a simple string manipulation.