Solved

Help with a regular expression for UK Phone Numbers

Posted on 2007-03-20
1
365 Views
Last Modified: 2008-03-06
I am having trouble getting a regular expression to work in mySQL. The expression came from http://regexlib.com/REDetails.aspx?regexp_id=593 but when I try and test it I get the following error:-

select count(*) from test.PHONE_NUMBERS where phone not regexp '^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$';
ERROR 1139 (42000): Got error 'repetition-operator operand invalid' from regexp

Any ideas?

0
Comment
Question by:chocobogo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
NovaDenizen earned 200 total points
ID: 18757362
That looks like a perl regexp, and mysql regexps are a little different.  See http://dev.mysql.com/doc/refman/5.0/en/regexp.html

\+ is intended to be the literal '+' character.  Mysql needs to see \\+ to get this right, because it does backslash escapes before it starts parsing the regexp.

\+ -> \\+

Same with \# and \( and \)

\# -> \\#
\( -> \\(
\) -> \\)

\d is intended to be a digit, and mysql doesn't support this method.  Use [0-9] instead.

\d -> [0-9]

\s is whitespace, not supported by mysql.  Use [[:space:]]

\s -> [[:space:]]

I think that covers all the dialect differences.  In the end the only backslashes present should be in the double-escaped literal (like \\#) patterns.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question