我想从文本中获取acestream url。我该如何创建这个正则表达式?
这里有一个例子:
<div class="md"><blockquote>
<p>acestream://5a2686630a7f6422d6edf02a197cbdf7c2695175</p>
</blockquote>
<p>720p version stuttering a lot for me, and I've got lightning connection speed</p>
</div>
如果URL包含十六进制字符,您可以使用类似的东西:
$subject = '<div class="md"><blockquote>
<p>acestream://5a2686630a7f6422d6edf02a197cbdf7c2695175</p>
</blockquote>
<p>720p version stuttering a lot for me, and I've got lightning connection speed</p>
</div>';
if (preg_match('~acestream://[0-9a-f]+~', $subject, $matches)) {
echo reset($matches);
}
产出:
acestream://5a2686630a7f6422d6edf02a197cbdf7c2695175
或者你可以用[0-9a-f]
替换[\w]
来获得字母,数字或下划线。