Skip to content

Instantly share code, notes, and snippets.

@uniqueginun
uniqueginun / extract_uuid.php
Created June 12, 2024 18:41
extract uuid from string - PHP
function extractUuid(string $string) {
$uuidPattern = '/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i';
$uuid = preg_match($uuidPattern, $string, $matches) ? $matches[0] : null;
return $uuid;
}
echo extractUuid("some other string 42344k-23423-dfs34-9--2342"); // null