Change US Phone number Format - REGEX?

I’m trying to change 1231231234 into 123 123-1234.
Can I use regex matches to do that? I put “(\d{3})(\d{3})(\d{4})”
Any digit exactly three times in the first capturing group… etc…
Then it returns an IEnumerable I guess I don’t know what that is returning exactly.
When I try to print out numberArray(0) It just prints the whole number exactly how it was entered
in the first place 1231231234 and the format doesn’t change.

What’s the best shortest way to do this.

You can use

PhNo = String1.substring(0,3) + " " + String1.substring(3,3) + “-” String1.substring(6,3)

2 Likes