Architect expression for phone number formatting failing

I’m trying to clean up phone numbers coming from our CRM integration before they hit the routing logic. The source sends them as E.164 strings like +15551234567, but I need them formatted as (555) 123-4567 for a specific downstream system. I’ve been wrestling with the expression builder in Architect. The standard string functions seem limited. I tried using substring combined with concat, but the logic is getting messy and error-prone. Here’s what I have so far:

concat(
 "(",
 substring(data.phoneNumber, 3, 3),
 ") ",
 substring(data.phoneNumber, 6, 3),
 "-",
 substring(data.phoneNumber, 9, 4)
)

The issue is that data.phoneNumber isn’t always clean. Sometimes it has leading spaces or the country code is different. When I run a test, if the input is just 5551234567 (missing the +1), the substring indices are off and I get garbled output like (55) 12-34567. I can’t seem to find a built-in formatPhone or regexReplace function in the expression editor. I checked the documentation, but it’s sparse on string manipulation examples. Is there a more solid way to handle this? Maybe a custom script action? I’m not a dev, so writing a full Node.js snippet feels overkill, but the expression approach is breaking on edge cases. I need a reliable way to strip non-numeric characters first, then pad or trim to ensure the length is correct before applying the substring logic. Any help would be appreciated. I’m stuck on this validation step.