Regex extract string after last point
im trying to extract every file extension of an uploaded file. For example:
example.doc -> .doc
another.example.jpeg -> .jpeg
even.anaother.example.pdf -> .pdf
i know this could be resolved by using regex, but regex are a closed book to me. So i开发者_如何学C need your help :( please
thanks in advance!
Try this regular expression:
\.[^.]*$
Alternatively, don't do regex but use a built-in: pathinfo()
$ext = pathinfo($path, PATHINFO_EXTENSION);
You can try with following regex:
^.*(\..*)$
in fact, this could be resolved by using nearly dozen methods. strrpos() + substr(), pathinfo(), explode()+end() are examples.
精彩评论