开发者

Regex extract string after last point

开发者 https://www.devze.com 2023-04-06 15:29 出处:网络
im trying to extract every file extension of an uploaded file. For example: example.doc -> .doc another.example.jpeg -> .jpeg

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

精彩评论

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