I need to format the existing phone numbers saved in my database. First, I need to clean the phone numbers with character.

```
801-113-1521

801.456.7891

1213-345-6789 ext 219

(323)567=2251

```

should be:

```
8011131521

8014567891

12133456789

3235672251

```

After, I will format it to (3 digit area code) ###-####
Then disregard the '1' country code for 11 digit numbers

I have tried 

```sql
DECLARE @string varchar(100)

SET @string = phoneNumber

-- loop till there are characters left in a string
WHILE PATINDEX('%[^0-9]%',@string) <> 0
BEGIN
    -- replace characters with empty space
    SET @string = STUFF(@string,PATINDEX('%[^0-9]%',@string),1,'')
END
SELECT @string

```

but when it comes to 1213-345-6789 ext 219, it includes 219. I am new to mssql.