Reformatting Text

I need to reformat text I have saved in a custom variable called PhoneNumber, it is currently formatted as the following (888) 888 - 8554, it needs to be changed to 888-888-8554.

Hi @gdsTechJay

First off, thanks for posting this question on the community. We’ve had a few customers ask similar questions, and I am thrilled to be able to answer this in a public forum where I can point future questions. Thank you!!

I suggest using a “Perform a Regular Expression Match” action step to extract the parts of the phone number, followed by a “Render Text and Store as Variable” step to create the new phone number.

Here’s how I recommend creating the “Perform a Regular Expression Match” step (assuming the phone number is currently available as {{}}):

The regular expression I used is:

/\((?<area>[2-9][0-9]{2})\) (?<prefix>[2-9][0-9]{2})\-(?<suffix>[0-9]{4})/

And you can see the example I built here:

The “Render Text and Store As Variable” could look like this:

The contents of the “Text to Render” field is:


In subsequent steps, you can simply insert {{custom.phone_formatted}} and you’ll have the newly-formatted phone number.

Let us know how that works!