簡體   English   中英

PHP:如何正則表達式替換以下字符串?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM