Archive for the ‘Perl’ Tag
Handy MySQL expression for finding phone numbers
We have a database where the phone number field apparently have been used for other information like notes. So how do I find there? As a Perl programmer I instantly think of regular expressions and to my joy the MySQL 5.0 we are running supports regular expressions!
Here is a nifty script to find what doesnt look like phone numbers in a table of MySQL 5.0:
select `phone` as apparently_not from `db`.`table` where `phone` not regexp ‘[. +-0123456789.]{5,}‘ and length(`phone`) > 0
This expression matches any series of 5 or more characters with numbers, plus, minus and space in them. It is crude but it will catch most phone numbers and since it is inverted show those that do not look like phone numbers. Also this expression excludes empty values.
Obviously you must changed “phone”, “db” and “table” to reflect the field, databasename and table of your database.
Leave a Comment
Leave a Comment