其实我有像追随者一样的字符串吗?
Physical Address Transport Name ===================
==========================================================
00-1F-29-A8-CA-54 Media disconnected
00-21-5C-68-BB-17 \Device\Tcpip_{1A76BCB8-6BD0-45AA-85B0-3016C3F82A5B}
请帮我从上面的字符串中仅过滤mac地址。谢谢你。
答案 0 :(得分:2)
使用preg_match_all
函数和POSIX字符类[:xdigit:]
的解决方案(将匹配所有十六进制数字):
// $str is your initial string
preg_match_all("/\b[[:xdigit:]]{2}-[[:xdigit:]]{2}-[[:xdigit:]]{2}-[[:xdigit:]]{2}-[[:xdigit:]]{2}-[[:xdigit:]]{2}\b/su", $str, $matches);
print_r($matches[0]);
输出:
Array
(
[0] => 00-1F-29-A8-CA-54
[1] => 00-21-5C-68-BB-17
)