Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having problems matching whitespace whith MySql REGEX

Tags:

regex

mysql

I'm trying to match all phones in a database which don't match with the format of this example '(11) 1234-5678'.

I'm having troubles defining a regexp because of the whitespace, I have done this tests:

SELECT '(11) 1234-5678' REGEXP "\([0-9]{2}\)" -> 1
SELECT '(11) 1234-5678' REGEXP "\([0-9]{2}\).*" -> 1
SELECT '(11) 1234-5678' REGEXP "\([0-9]{2}\) " -> 0
SELECT '(11) 1234-5678' REGEXP "\([0-9]{2}\)[:blank:]" -> 0
SELECT '(11) 1234-5678' REGEXP "\([0-9]{2}\)[:space:]" -> 0

I have absolutely no idea of why I can't get mysql to match a whitespace.

EDIT:

I'm using mysql 5.5.24

like image 563
hchinchilla Avatar asked Oct 04 '12 09:10

hchinchilla


1 Answers

Use:

SELECT '(11) 1234-5678' REGEXP "\\([0-9]{2}\\)[[:space:]]"
like image 92
xdazz Avatar answered Sep 23 '22 12:09

xdazz