Thoman
Thoman

Reputation: 792

MySQL Regexp to match image links

I tried this expression

 SELECT * FROM `table` WHERE COL REGEXP "^([%\w-]+\.(?:jpe?g¦JPE?G¦gif¦GIF¦png¦PNG))$"

Please help me

Upvotes: 3

Views: 1418

Answers (1)

g13n
g13n

Reputation: 3246

@Thoman I assume that the column stores image paths, in which case you could just look for column having the ".jpg", etc. extension as opposed to matching the whole path.

SELECT * FROM `table` WHERE col REGEXP '\.(jpe?g|gif|png)'

If you have the col with values like /tmp/foo.gif then it wouldn't match the \w+ (word characters expression.)

Hope this helps.

Upvotes: 3

Related Questions