Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Regexp to match image links

Tags:

regex

mysql

I tried this expression

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

Please help me

like image 962
Thoman Avatar asked Dec 05 '25 02:12

Thoman


1 Answers

@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.

like image 162
g13n Avatar answered Dec 08 '25 17:12

g13n



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!