I want to get the version number for some string in php. Here is the sample code
<?php
function getVersion($str) {
preg_match("/.*((?:[0-9]+\.?)+)/i", $str, $matches);
return $matches[1];
}
print_r(getVersion("ansitl1-isam-6.0 1.0 9.7.03 418614 +"));
print_r(getVersion("ams-ef 9.6.06ef4 - 394867"));
?>
for input string ansitl1-isam-6.0 1.0 9.7.03 418614 + output should be 9.7.03
for input string ams-ef 9.6.06ef4 - 394867 output should be 9.6.06
How to achieve this?
(?<= )\d+\.\d+\.\d+