YeppThat'sMe
YeppThat'sMe

Reputation: 1862

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 need your help :( please

thanks in advance!

Upvotes: 2

Views: 1415

Answers (4)

jensgram
jensgram

Reputation: 31508

Alternatively, don't do regex but use a built-in: pathinfo()

$ext = pathinfo($path, PATHINFO_EXTENSION);

Upvotes: 5

Your Common Sense
Your Common Sense

Reputation: 157889

in fact, this could be resolved by using nearly dozen methods. strrpos() + substr(), pathinfo(), explode()+end() are examples.

Upvotes: 1

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56172

Try this regular expression:

\.[^.]*$

Upvotes: 7

hsz
hsz

Reputation: 152236

You can try with following regex:

^.*(\..*)$

Upvotes: 1

Related Questions