PHP regex last occurrence of words

Viewed 448

My string is: /var/www/domain.com/public_html/foo/bar/folder/another/..

I want to remove the root folder from this string, to get only public folder, because some servers have multiple websites inside.

My actual regex is: /^(.*?)(www|public_html|public|html)/s

My actual result is: /domain.com/public_html/foo/bar/folder/another/..

But i want to remove the last ocorrence, and get somethig like this: /foo/bar/folder/another/..

Thanks!

2 Answers
Related