Architect expression regex replace for phone number formatting

My configuration keeps failing…

I need to format a phone number from +1XXXXXXXXXX to (XXX) XXX-XXXX in an Architect Data Action. I am migrating from Five9 where this was trivial, but GC expressions are finicky.

  1. Input variable input.phone contains +15551234567
  2. Using expression: replace(replace(replace(input.phone, "+1", ""), "(\d{3})(\d{3})(\d{4})", "(\1) \2-\3"), "", "")
  3. Result is empty or malformed.

Is the regex syntax in Architect expressions different? My code block returns null.

The main issue here is that Architect expressions do not support backreference capture groups like \1. The replace function in GC is strictly for literal string substitution, not regex capture groups. You are trying to use JavaScript syntax inside a platform engine that only handles basic pattern matching. This is a common pitfall when migrating from more flexible scripting environments.

You need to break the formatting into multiple steps using the substring function. It is clunky, but it works reliably within the Architect constraints. You must isolate each segment of the phone number by character index. Ensure your input is stripped of the country code first.

  1. Strip the prefix: replace(input.phone, "+1", "")
  2. Extract Area Code: substring(cleanPhone, 0, 3)
  3. Extract Prefix: substring(cleanPhone, 3, 3)
  4. Extract Line Number: substring(cleanPhone, 6, 4)

Concatenate these with your desired formatting. Use this expression:
"(" + substring(replace(input.phone, "+1", ""), 0, 3) + ") " + substring(replace(input.phone, "+1", ""), 3, 3) + "-" + substring(replace(input.phone, "+1", ""), 6, 4)

Make sure you stop fighting the expression engine and handle this in PowerShell instead. Just fetch the data via Get-CsUser, format the string locally using -replace '^\+\d{1,2}(\d{3})(\d{3})(\d{4})', '($1) $2-$3', and write it back using Update-CsUser with the correct OAuth scopes.