<?php
$version = '5.5.58-0ubuntu0.14.04.1';
echo '<pre>';
var_dump(preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts));
if (!preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
echo "RegEx failed on " . $version . PHP_EOL;
} else {
echo "RegEx extracted version parts" . PHP_EOL;
var_dump($versionParts);
}
function errorValue($error)
{
return defined($error) ? constant($error) : $error;
}
$errors = array(
'PREG_NO_ERROR',
'PREG_INTERNAL_ERROR',
'PREG_BACKTRACK_LIMIT_ERROR',
'PREG_RECURSION_LIMIT_ERROR',
'PREG_BAD_UTF8_ERROR',
'PREG_BAD_UTF8_OFFSET_ERROR',
'PREG_JIT_STACKLIMIT_ERROR'
);
$pregErrors = array_combine(
array_map('errorValue', $errors),
$errors
);
echo $pregErrors[preg_last_error()] . PHP_EOL;
echo '</pre>';
preferences:
36.35 ms | 410 KiB | 5 Q