tags:

views:

41

answers:

2

I need a MySQL query w/ Regex to tell me if my string's first character is a number from 0 to 9.

+5  A: 

The following query returns '1', since the REGEXP matches. You can adapt it for your purposes:

SELECT '123 this starts with a digit' REGEXP '^[[:digit:]]';

You can use it in a SELECT like this:

SELECT * FROM tbl WHERE field REGEXP '^[[:digit:]]';
zombat
+2  A: 
SELECT 'a12' REGEXP '^[0-9]';
=> 0
SELECT '4ab' REGEXP '^[0-9]';
=> 1
Simon Buchan