PHP从字符串中提取

时间:2014-09-03 10:59:24

标签: php regex

我是php的新手,需要提取" url"来自以下字符串

href = \" https://www.youtube.com/watch?v=gYDSNteP_60 \">胖子,我?我只是横向挑战"

不同网址的网址长度会有所不同

任何帮助。

由于

4 个答案:

答案 0 :(得分:1)

这将返回URL作为唯一匹配:

/(?<=href=").+?(?=")/i

答案 1 :(得分:0)

href.*\/\/(.*?)\\

你可以使用它。参见演示。

http://regex101.com/r/pP3pN1/24

答案 2 :(得分:0)

试试这个

$string ="href=\"https://www.youtube.com/watch?v=gYDSNteP_60\">Fat, me? I'm just horizontally challenged";
$regex = '/https?\:\/\/[^\" ]+/i';
preg_match_all($regex, $string, $matches);
print_r($matches[0]);

答案 3 :(得分:0)

将regexp与this

一起使用
href=\\(.*)>