php:如何正则表达式替换以下字符串?

时间:2012-01-27 08:07:21

标签: php regex

想要替换所有出现的双引号

"http://somebunchofchar"

"link"

我想出了preg_replace("/\"http:\/\/.\"/i", "\"link\"", $string);

4 个答案:

答案 0 :(得分:2)

只需在点

后添加星号和问号即可

preg_replace("/\"http:\/\/.*?\"/i", "\"link\"", $string);

答案 1 :(得分:2)

$string = preg_replace('#"http://.+"#', '"link"', $string);

答案 2 :(得分:1)

您可以使用:

preg_replace('~"http://[^"]*"~i', '"link"', $string);

答案 3 :(得分:0)

看看这里: http://regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2&AspxAutoDetectCookieSupport=1 如何使用正确的模式匹配URL;比使用具有特定正则表达式模式的preg_replace ;-)(您可以很容易地在开头和结尾处添加这些引号): - )

相关问题