citizenen
citizenen

Reputation: 703

Regex MySQL - Match First Two letters, x Numbers

Looking to match any rows in a MySQL database where VectorId starts with 'TS' followed by any amount of numbers, min 1. I want to match TS1, TS1234, etc but not TS (by itself), T12 or V124.

So far I have:

SELECT * FROM T3_SeriesInfo WHERE VectorId LIKE '^TS\d+' ORDER BY VectorId DESC

Any ideas?

Upvotes: 1

Views: 1561

Answers (2)

FreudianSlip
FreudianSlip

Reputation: 2920

Try:

SELECT * FROM T3_SeriesInfo WHERE VectorId REGEXP '^TS\d*' ORDER BY VectorId DESC

Upvotes: 0

Richard
Richard

Reputation: 4415

Have you looked at the manual? http://dev.mysql.com/doc/refman/5.1/en/regexp.html

Something like this:

SELECT * FROM T3_SeriesInfo WHERE VectorId REGEXP '^TS[[:digit:]]+' ORDER BY VectorId DESC

Upvotes: 2

Related Questions