For you example string you might match what is between parenthesis using \(\K[^)]+(?=\))
.
This will match an opening parenthesis \(
and then use \K
to reset the starting point of the reported match.
After that match NOT a closing parenthesis one or more times [^)]+
and a positive lookahead to assert that what follows is a closing parenthesis (?=\))
.
Then you could create a DateTime using or use DateTime::createFromFormat using $matches[0]
and extract the time:
$re = '/\(\K[^)]+(?=\))/';
$str = 'Updated by Carewina Almonte (04/02/2018 21:58:32)';
preg_match($re, $str, $matches);
$dateTime = new DateTime($matches[0]);
if ($dateTime !== false) {
echo $dateTime->format('H:i:s');
}
Test