Stuck on a regex replacement in Architect. Trying to convert a source number +1XXXXXXXXXX to (XXX) XXX-XXXX for a downstream IVR. The standard regexp_replace function seems to be eating the area code or returning null on specific inputs.
Here’s the expression:
regexp_replace(data.phoneNumber, "^\\+1(\\d{3})(\\d{3})(\\d{4})$", "(\\1) \\2-\\3")
It works fine in my local test harness with Node.js, but inside Architect, it returns the original string untouched if there’s any whitespace or if the + isn’t strictly at the start. I’ve tried escaping the + differently and stripping whitespace first with trim(), but the logic feels brittle.
Is there a known quirk with how Architect handles the ^ anchor or unicode digits in these expressions? The docs are pretty thin on edge cases for phone normalization. Just looking for a more reliable pattern that won’t break on minor formatting variations in the incoming CDR data.