$s = '<a href="aa.html" target="_self">';
echo preg_replace("/<a\s+href=['\"]?([\w.]+)['\"]?/i","<a href=\"a(\\1)\"",$s);

解决方案 »

  1.   

    可能我的表达方式有点出入。
    我的目的是把<a href="aa.html" target="_self">用查找替换的原则
    替换成<a href="a(aa.html)" target="_self">.但是后面的target="_self" 可能存在或不存在,这样实现整站替换
      

  2.   

    $s = '<a href="aa.html" target="_self">';
    echo preg_replace("/<a\s+href=['\"]?([\w.]+)['\"]?/i","<a href=\"a(\\1)\"",$s);难道这个不行吗?
      

  3.   

    可以了/<a .*href="(.*?)"/谢谢啊!
      

  4.   

    <?php
    $url= '<a href="aa.html" target="_self">';
    $url= preg_replace('/"(.+?)"(.+)/', '"a(\1)">', $url, 1);
    echo $url;
    ?>