Skip to content

Instantly share code, notes, and snippets.

@jassriver
Created March 9, 2021 23:48
Show Gist options
  • Save jassriver/631bb210100693f326c8fd832ee6ae39 to your computer and use it in GitHub Desktop.
Save jassriver/631bb210100693f326c8fd832ee6ae39 to your computer and use it in GitHub Desktop.
Extrai um endereço de MAC de uma string usando Regex (Expressão regular) com PHP
<?php
// String obtida
$macAddress = '10.19.60.72 --- 0x3 Endereço IP Endereço físico Tipo 10.19.63.117 70-85-c2-f6-28-f8 dinâmico';
// Expressão regular pra extrair o MAC ADDRESS
preg_match_all('/[a-fA-F0-9-]{17}|[a-fA-F0-9]{12}$/', $macAddress, $mac);
// Printa o resultado
print_r($mac);
/*
Resultado:
Array ( [0] => Array ( [0] => 70-85-c2-f6-28-f8 ) )
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment