Yes, regex is the way to go. Alternatively, you could split around the "."
and check the last element in the returned array against an array of image extensions. I'm not a PHP guy so I can't write the code for you, but I can write the regex:
^[a-zA-Z\.0-9_-]+\.([iI][mM][gG]|[pP][nN][gG]|etc....)$
This one is fairly simple. I know you don't have much experience with regex, but here's what this one does:
^: start of string
[a-zA-Z\.0-9_-]: describes range of characters including all letters, numbers, and ._-
\.: "." character
([iI][mM][gG]|[pP][nN][gG]|etc....): | means or. So just put all image extensions you know here. Again, the brackets for case-insensitivity
if you want to match any sequence then instead of the stuff in the brackets and the +, just use:
.*
"." matches any character and "*" means any amount of it. So this just basically says "no restrictions" (except newlines)
There are probably a lot of other things I'm missing, as you can see in the comments. Just read those, look at a regex reference, and you'll be fine.