求一正则表达式替换
<a href="http://www.baidu.com.com" >baidu</a>
如上字符串中标签外的baidu 为<b>baidu</b>
------解决方案--------------------
- PHP code
$s = 'baid,baidu,baidu,google,baidu <a href="http://www.baidu.com"> baidu </a> sdfsdf www.baidu.com '; echo preg_replace("/(?<!www\.)(baidu)(?!\.com)/","<b>\\1</b>",$s);
------解决方案--------------------
$search = array("/(.*)([^\.]baidu[^\.])(.*)/", "/(.*)([^\.]baid[^\.])(.*)/", "/(.*)([^\.]google[^\.])(.*)/");
$replace = "\$1<b> baidu </b>$3";
$str = '<a href="http://www.baidu.com.com" > baidu baid </a><a href="http://www.baidu.com.com" > 12312 google </a>';
$res = preg_replace( $search, $replace, $str );
exit($res);
------解决方案--------------------
貌似PHP里有反向预查,那样的话,很简单的就可以解决了...:D
飘走...