Dims
Dims

Reputation: 51039

digit character class in regexp doesn't work in MySQL for me

The following query

SELECT "T2N1M0" REGEXP "^T[:digit:].*";

returns single row with 0 for me.

I would expect it return 1.

What I am doing wrong?

Upvotes: 1

Views: 790

Answers (1)

Emil Vikström
Emil Vikström

Reputation: 91942

You are missing one level of square brackets []:

SELECT "T2N1M0" REGEXP "^T[[:digit:]].*";

You should have gotten this error message that hints at the problem:

Got error 'POSIX named classes are supported only within a class at offset ' from regexp

More one the syntax for regular expressions are given by the manual page 13.5.2 Regular Expressions.

Upvotes: 2

Related Questions