如何创建acestream正则表达式[关闭]

问题描述 投票:-1回答:1

我想从文本中获取acestream url。我该如何创建这个正则表达式?

这里有一个例子:

    <div class="md"><blockquote>
<p>acestream://5a2686630a7f6422d6edf02a197cbdf7c2695175</p>
</blockquote>

<p>720p version stuttering a lot for me, and I&#39;ve got lightning connection speed</p>
</div>
php regex
1个回答
2
投票

如果URL包含十六进制字符,您可以使用类似的东西:

$subject = '<div class="md"><blockquote>
<p>acestream://5a2686630a7f6422d6edf02a197cbdf7c2695175</p>
</blockquote>
<p>720p version stuttering a lot for me, and I&#39;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]来获得字母,数字或下划线。

© www.soinside.com 2019 - 2024. All rights reserved.