1

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?

3
  • LOL! Yep that worked, as I said my regex knowledge is very limited - that works a treat, thankyou. =D Commented Feb 4, 2015 at 12:50
  • 1
    Then I suggest you read a bit about regexes and what the chars and groups like ^, $ and {2} mean. For example www.regular-expressions.info can be a good start. :-) Commented Feb 4, 2015 at 12:52
  • Thanks, I will do - I've always got by using PHP functions but theres no avoiding them for complex selects in MySQL :) Commented Feb 4, 2015 at 12:54

1 Answer 1

2
^[A-Z]{2}

Try this.This should do it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.