RayZor
RayZor

Reputation: 665

MySQL query to find out if part of a string is not numeric

I'm trying to find a way to run a query which selects where the first two characters of an eight character string are Not numeric.

I've found a way to select if the entire string is numeric:

SELECT str FROM tbl
WHERE str REGEXP('(^[0-9]+$)');

So from my limited knowledge of regex I'm guessing that I'll need to use something like:

SELECT str FROM tbl
WHERE str REGEXP('(^[A-Z]+$)');

(I'm OK to use capitals for this as thats how the codes are stored)

I just don't know how to apply this test to just the first 2 characters of the string instead of the entire string?

Upvotes: 1

Views: 39

Answers (1)

vks
vks

Reputation: 67968

^[A-Z]{2}

Try this.This should do it.

Upvotes: 2

Related Questions