How to get the last digits that are numbered before '.html' string

advertisements

there is a string, for example : http://address.com/sef-title-of-topic-1111.html

i could not get 1111 in anyway with regexp in php. Is it possible? How?

my code:

$address = 'http://address.com/sef-title-of-topic-1111.html';

preg_match('#-(.*?)\.html#sim',$address,$result);


If the url example is how they will always appear (ie. ending in hyphen, numbers, .html) then this should work:

$str = "http://address.com/sef-title-of-topic-1111.html";

preg_match('#.*-(\d+)\.html#', $str, $matches);
print_r($matches);

If they won't always match the pattern you gave in your question, then clarify by showing alternative values for your $address value.