Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with a regular expression for UK Phone Numbers

Posted on 2007-03-20
1
Medium Priority
?
372 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 800 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

715 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