Question: How can I check if specific path match to pattern.

Example:

I have a path with one or more unknown variable

```
$pathPattern = 'user/?/stats';

```

And let say I received this path

```
$receivedPath = 'user/12/stats'

```

So, how can I check if that received path match to my pattern?

I tried to do something like below but didn't work.

```
 $pathPattern = 'user/?/stats';
 $receivedPath = 'user/12/stats';

 $pathPatternReg = str_replace('?','.*',$pathPattern);
 echo preg_match('/$pathPatternReg/', $receivedPath);

```

Thank you.

Answer: 
Regex should be something like this for a unknown `user\/[0-9]+\/stats`

And Could be used as such;

`if(preg_match("user\/[0-9]+\/stats",$variable)) { .... }`
Thank you booth. 
This is a solution:

```
$pathPattern = 'user/?/stats';
$receivedPath = 'user/12/stats';

$pathPatternReg = str_replace(['/','?'],['\/','.*'],$pathPattern);
$pattern = "/^$uri/";
echo preg_match($pattern, $receivedPath);

```