Help with MySQL Regular Expression - Grabbing the Year
I've never been very good with regular expression - and I'm looking for someone to help building a simple regex for MYSQL that queries DB for the following pattern:
Could be anything here (YYYY)
Basically - I want to be able to query the DB to return all rows that mat开发者_如何学运维ch that pattern.
Sample Query:
SELECT title from myTable where title REGEX '$(YYYY)$'
Any advice or help on this?
UPDATE: The YYYY entry is a Year, like 2011 or 2010. Sorry for the confusion.
This should do the trick:
SELECT title from myTable where title REGEXP '[(][0-9]{4}[)]'
(By the way, it's REGEXP
with a P)
Not sure what exactly you are looking for but try this one:
SELECT title from myTable where title REGEXP '.*\([0-9]{4}\).*'
EDIT: Too slow:) Use Vache answer.
SELECT title from myTable where title REGEXP '[(][0-9]{4}[)]'
See: http://dev.mysql.com/doc/refman/5.1/en/regexp.html
and: http://www.go4expert.com/forums/showthread.php?t=2337
For more info.
How about the simple (but a little slow)
SELECT * FROM table WHERE field LIKE '%yyyy%';
The % sign is the wildcard so this samplequery would return any rows where "field" contains 'yyyy'.
E.g:
yyyyfoobar or fooyyyybar or fooyyyy
would all be found by this query.
Disregard this answer, since it was posted before the clarification Edit.
精彩评论