Niklas Riecken Niklas Riecken - 7 months ago 18
PHP Question

Preg Match Extracting

I want to extract a string out of a string.

I have the following String:

"date-x-days"


I would like to extract the
"x"
, which could be any int value

I already tried this pattern: ~(date-)*(-days)~
But its only giving me "date-" and "-days" back, but I want to receive the number.

How can I do this?

Cheers,
Niklas

Answer
$returnValue = preg_match('/-(\d+)-/', '[date-454-days]', $matches);
print_r($matches);