简体   繁体   English

正则表达式替换所有字符串,排除特殊前缀

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM