开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜