本文介绍了PHP preg_match UUID v4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,其中包含 UUID v4

I've got a string that contains UUID v4

$uuid = 'http://domain.com/images/123/b85066fc-248f-4ea9-b13d-0858dbf4efc1_small.jpg';

我如何使用preg_match()从上面获取b85066fc-248f-4ea9-b13d-0858dbf4efc1值?
可以在此处

How would i get the b85066fc-248f-4ea9-b13d-0858dbf4efc1 value from the above using preg_match()?
More info on UUID v4 can be be found here

推荐答案

$uuid = 'http://domain.com/images/123/b85066fc-248f-4ea9-b13d-0858dbf4efc1_small.jpg';
preg_match('!/images/\d+/([a-z0-9\-]*)_!i', $uuid, $m);

还有

preg_match('/[a-f0-9]{8}\-[a-f0-9]{4}\-4[a-f0-9]{3}\-(8|9|a|b)[a-f0-9]{3‌​}\-[a-f0-9]{12}/', $uuid, $m);

也可以.取自此处,但我不知道不知道我们是否可以依靠它.

works too. Taken from here, but I don't know if we can rely on that.

这篇关于PHP preg_match UUID v4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:16