[英]regex replace all strings exclude special prefix
I want to replace a tag but only, if there is not a special prefix. 我只想替换一个标签,如果没有特殊的前缀。 I need to replace the href
but not the data-orig
我需要替换href
而不是data-orig
$string = "Some gibberish here <a href='###REPLACEME:needed###' data-orig-href='###REPLACEME:needed###'>url</a>" ;
$pattern = "/###REPLACEME:(.*)###/";
$replace = "http://somerealurl.dev";
$string = preg_replace($pattern, $replace, $string);
I have no idea how I can realize this pattern. 我不知道如何实现这种模式。
解决了
$pattern = '/(?<!data-orig-href=")###REPLACE:(.*?)###/';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.