如何用php替换字符串

时间:2016-04-12 22:08:56

标签: php regex

我需要替换这种字符串:

https://r2---sn-vgqs7nez.c.docs.google.com/
https://r2---sn-testne4.c.docs.google.com/
https://r5---sn-vfghtgh.c.docs.google.com/

到这个

https://redirector.googlevideo.com/

使用php,请帮帮我

1 个答案:

答案 0 :(得分:1)

您可以使用此正则表达式搜索和替换

$pattern = '/^(https:\/\/)[a-zA-Z0-9\-.]+.docs.google.com\//g';
preg_replace($pattern, 'https://redirector.googlevideo.com/', $yourstring);

证明: http://regexr.com/3d71p