PDA

View Full Version : MySQL REGEX Query


BamaStangGuy
28 Oct 2007, 09:49
I am running this query:
$result_date = $vbulletin->db->query_read("
SELECT DISTINCT
z.tag, COUNT(*) AS total_lyrics
FROM " . TABLE_PREFIX . "zoints_tag AS z
LEFT OUTER JOIN " . TABLE_PREFIX . "thread AS t
ON z.threadid = t.threadid
WHERE t.forumid = 34 AND z.tag REGEXP '^[0-9]'
GROUP BY z.tag
ORDER BY z.tag
");

With the goal of retrieving every tag that starts with 0-9. I have one tag in there right now that starts with a 3, '3 doors down'.

However the above query does not return any results. Is that the correct format and if so what would be causing it to return nothing at all?

Marco van Herwaarden
28 Oct 2007, 14:03
'^[0-9]'

This means that the data should start with a single digit number and nothing after that.

try:

'^[0-9].*'

BamaStangGuy
28 Oct 2007, 20:50
I figured it out. I had a misspelling lol.

Thanks for the help though, I did need to adjust the regex.