Hello there,
Given the following string how can I match the entire number at the end of it?
$string = "Conacu P PPL Europe/Bucharest 680979";
I have to tell that the lenght of the string is not constant.
My language of choice is PHP.
Thanks.
Hello there,
Given the following string how can I match the entire number at the end of it?
$string = "Conacu P PPL Europe/Bucharest 680979";
I have to tell that the lenght of the string is not constant.
My language of choice is PHP.
Thanks.
Hi,
You could use a regex with preg_match
, like this :
$string = "Conacu P PPL Europe/Bucharest 680979";
$matches = array();
if (preg_match('#(\d+)$#', $string, $matches)) {
var_dump($matches[1]);
}
And you'll get :
string '680979' (length=6)
And here are some informations :
#
at the begining and the end of the regex are the delimiters -- they don't mean anything : they just indicate the begining and end of the regex ; and you could use whatever character you want (people ofen use /
)()
means you want to capture what is between them
preg_match
, the array given as third parameter will contain those captured data()
\d
means "a number"+
means one or more timeSo :
For more informations, you can take a look at PCRE Patterns and Pattern Syntax
.