[英]php: how to regex replace the following strings?
想替换所有出现的情况,包括双引号
"http://somebunchofchar"
至
"link"
我想出了preg_replace("/\\"http:\\/\\/.\\"/i", "\\"link\\"", $string);
只需在点后添加星号和问号
preg_replace("/\\"http:\\/\\/.*?\\"/i", "\\"link\\"", $string);
$string = preg_replace('#"http://.+"#', '"link"', $string);
您可以使用:
preg_replace('~"http://[^"]*"~i', '"link"', $string);
只需看这里: http : //regexlib.com/DisplayPatterns.aspx ?cattabindex=1&categoryId=2& AspxAutoDetectCookieSupport=1如何将URL与正确的模式进行匹配; 而不是将preg_replace与特定的regexp模式一起使用;-)(您可以很容易地在模式的开始和结束处添加这些引号):-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.