preg_replace with Regex - 在URL中查找数字序列

I'm a regex-noobie, so sorry for this "simple" question:

I've got an URL like following:

http://stellenanzeige.monster.de/COST-ENGINEER-AUTOMOTIVE-m-w-Job-Mainz-Rheinland-Pfalz-Deutschland-146370543.aspx

what I'm going to archieve is getting the number-sequence (aka Job-ID) right before the ".aspx" with preg_replace.

I've already figured out that the regex for finding it could be

(?!.*-).*(?=\.)

Now preg_replace needs the opposite of that regular expression. How can I archieve that? Also worth mentioning:

The URL can have multiple numbers in it. I only need the sequence right before ".aspx". Also, there could be some php attributes behind the ".aspx" like "&mobile=true"

Thank you for your answers!

You can use:

$re = '/[^-.]+(?=\.aspx)/i'; 
preg_match($re, $input, $matches);
//=> 146370543

This will match text not a hyphen and not a dot and that is followed by .aspx using a lookahead (?=\.aspx).

RegEx Demo

You can just use preg_match (you don't need preg_replace, as you don't want to change the original string) and capture the number before the .aspx, which is always at the end, so the simplest way, I could think of is:

<?php
$string = "http://stellenanzeige.monster.de/COST-ENGINEER-AUTOMOTIVE-m-w-Job-Mainz-Rheinland-Pfalz-Deutschland-146370543.aspx";
$regex = '/([0-9]+)\.aspx$/';
preg_match($regex, $string, $results);
print $results[1];
?>

A short explanation:

$result contains an array of results; as the whole string, that is searched for is the complete regex, the first element contains this match, so it would be 146370543.aspx in this example. The second element contains the group captured by using the parentheeses around [0-9]+.

You can get the opposite by using this regex:

(\D*)\d+(.*)

Working demo

MATCH 1
1.  [0-100] `http://stellenanzeige.monster.de/COST-ENGINEER-AUTOMOTIVE-m-w-Job-Mainz-Rheinland-Pfalz-Deutschland-`
2.  [109-114]   `.aspx`

Even if you just want the number for that url you can use this regex:

(\d+)