I have a table which has a field (phone_number (tinytext)) that contains phone numbers in a variety of unpredictable, non-standard formats, just however they were keyed in. Unfortunately, I didn't create nor can I change the data set. Example:
+---+------------------+
| id| phone_number |
+---+------------------+
| 1 | (999) 999-9999 |
| 2 | +19999999979 |
| 3 | 999-999-9979 |
| 4 | (999)999-9999 |
| 5 | 999/999/9999 |
| 6 | 99-9999-9999 |
| 7 | (999-9999999 |
+---+------------------+
What I need to be able to do is, given a string of straight digits (i.e., 9999999979), I need to find the row(s) that contain the same digits, in the same order.
So, for my generic example, I want to match row 2 and 3 because they both have all the digits, in order (once non-numeric characters are removed). Basically I need a way to match but first remove any non-numeric characters.
I have tried REGEXP, REGEX_REPLACE, FIND_IN_SET, but can't seem to make any of them work.
I am looking for something like this (which of course doesn't work):
SELECT * from phone_data WHERE phone_number REGEXP '^?![0-9]$' LIKE '%9999999979%'