$re = '/^(.*?)\.((?:\.?[0-9]+){3,}(?:[-a-z]+)?)\.nupkg$/m';
$str = 'knockoutjs.3.4.2.nupkg
log4net.2.0.8.nupkg
runtime.tizen.4.0.0-armel.microsoft.netcore.jit.2.0.0.nupkg
nuget.core.2.7.0-alpha.nupkg
microsoft.identitymodel.6.1.7600.16394.nupkg
Package: knockoutjs Version: 3.4.2
Package: log4net Version: 2.0.8
Package: runtime.tizen.4.0.0-armel.microsoft.netcore.jit Version: 2.0.0
Package: nuget.core Version: 2.7.0-alpha
Package: microsoft.identitymodel Version: 6.1.7600.16394
';
$subst = "Package: \1 Version: \2";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php