Home > Backend Development > PHP Tutorial > 求一正则表达式解决办法

求一正则表达式解决办法

WBOY
Release: 2016-06-13 10:03:36
Original
1091 people have browsed it

求一正则表达式
求一正则表达式替换
baidu
如上字符串中标签外的baidu 为baidu

------解决方案--------------------

PHP code
$s = 'baid,baidu,baidu,google,baidu <a href="http://www.baidu.com"> baidu </a> sdfsdf www.baidu.com ';echo preg_replace("/(?\\1",$s);<br><font color="#e78608">------解决方案--------------------</font><br>$search  = array("/(.*)([^\.]baidu[^\.])(.*)/", "/(.*)([^\.]baid[^\.])(.*)/", "/(.*)([^\.]google[^\.])(.*)/");<br>$replace = "\$1<b> baidu </b>$3";<br>$str = '<a href="http://www.baidu.com.com"> baidu baid </a><a href="http://www.baidu.com.com"> 12312 google </a>';<br>$res = preg_replace( $search, $replace, $str );<br>exit($res);<br><br><font color="#e78608">------解决方案--------------------</font><br>貌似PHP里有反向预查,那样的话,很简单的就可以解决了...:D<br>飘走...<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template