Adding dashes to phone number output

We currently have a form that client’s fill out to submit tickets and the phone number we capture comes in like the following: +1xxxxxxxxxx, with the x’s being the phone number. I am currently trying to figure out how to add a space (or a -) after +1 and dashes between the numbers so it looks like a phone number and is easier on the eyes. ex. +1 123-123-1234 or +1-123-123-1234,

I am not an expert on regex expressions, but trying to learn from my existing code and using ChatGPT to guide me. ChatGPT was able to get me some code that seemed to work within ChatGPT, but whenever I replace it in Email2AT, it destroys my submission in Autotask. Below is the current expression and what ChatGPT suggested. Any ideas on what I’m missing? I also tried countless variations, but couldn’t get one to work.

Current:
Best phone number to reach you at:
{{between_strings email.bodyparts.html_to_plaintext “\nBest phone number to reach you\n” “\nSubject\n” flags=“t”}}

ChatGPT suggestion:

{{regex_find (between_strings email.bodyparts.html_to_plaintext “\nBest phone number to reach you\n” “\nSubject\n” flags=“t”) “+1\s?\d{3}-\d{3}-\d{4}”}}

I’m sure to a trained eye they will know what is wrong, or tell me that ChatGPT has no idea what they are talking about. Any advice would be welcomed.

@bayon

Thanks for posting!

Before I answer the question, I am very curious what prompt you used for ChatGPT to get that answer. It’s not a correct answer, but ChatGPT obviously knew something about the MSPintegrations syntax because it was close. Thanks!

I would recommend a distinct “Perform a Regular Expression Match” action step in your rule.

Here’s the regular expression I would use:

/\+1(?<area_code>\d{3})(?<prefix>\d{3})(?<suffix>\d{4})/

If you want to understand how that expression works, check out my working copy at regex101.com (my favorite regex debugging site). Hover the expression parts in the top and see what each part means.

You would create the step in MSPintegrations like this:

When this action is executed, it will first render the Subject, and then will match the Pattern and store the results in Store results in variable.

In a subsequent step, you can display the phone number with the following syntax:

+1{{custom.phone_number.area_code}}-{{custom.phone_number.prefix}}-{{custom.phone_number.suffix}}

Let us know how that works for you!

Thank for you for the information. As for ChatGPT, I first posted one of our email submission for it to reference. Then I gave it your existing code to extract the phone number, which it recognized and replicated the output I needed. I then asked it to add dashes to make it look like a phone number, which then got me to the code I posted here. I then played with a bunch of variations of the request to try and get it to work.

I was using the free ChatGPT 3.5, unsure if v4 would have done any better.

Let me play with this and see what I can figure out on my own.

1 Like