I have a url, - "http://example.com/sales/view/id/705
" and I need get a last segment (705).
How can I do this using PCRE?
I have a url, - "http://example.com/sales/view/id/705
" and I need get a last segment (705).
How can I do this using PCRE?
(In PHP) I would not use PCRE for such a trivial and un-ambiguous job. I would just do:
$parts = explode('/', rtrim($url, '/'));
$partYouWant = array_pop($parts);
EDIT
If you need to use PCRE (although I don't know why you would) this variation on eugene y's answer would do it:
$pattern = '#/([^/]+)\z#';
$url = 'http://example.com/sales/view/id/705';
preg_match($pattern, $url, $matches);
echo $matches[1];