这是我在 .NET 下写的正则表达式,如下"href=(?<web_url>[\s\S]*?)>|href=""(?<web_url>[\s\S]*?)""|href='(?<web_url>[\s\S]*?)'"目的就是要得到,一个指定 URl (如:http://shop.ebay.com/merchant/aboutsales)中所有连接信息,在.NET运用该正则表达式,可得到如下类似的Url/merchant/aboutsales_W0QQQ5ftrkparmsZ72Q253A1205Q257C66Q253A2Q257C65Q253A12Q257C39Q253A1QQ_trksidZp3911Q2ec0Q2em14?_pgn=3
/merchant/aboutsales_W0QQQ5ftrkparmsZ72Q253A1205Q257C66Q253A2Q257C65Q253A12Q257C39Q253A1QQ_trksidZp3911Q2ec0Q2em14?_pgn=4
http://cgi.ebay.com/Tory-Burch-Ella-Coconut-Blue-Wedge-Peep-Toe-Shoes-6-5-M_W0QQitemZ270342109810QQcmdZViewItemQQptZUS_Women_s_Shoes?hash=item3ef1a53a72&amp;_trksid=p3911.c0.m14&amp;_trkparms=72%3A1205%7C66%3A2%7C65%3A12%7C39%3A1%7C240%3A1318%7C301%3A0%7C293%3A1%7C294%3A50
http://jewelry.shop.ebay.com/items/Jewelry-Watches__W0QQ_catrefZ1QQ_flnZ1QQ_sacatZ281QQ_ssnZaboutsalesQQ_trksidZp3911Q2ec0Q2em282
http://cgi.ebay.com/New-Auth-Kate-Spade-Harwyn-Sm-Maya-Leopard-Purse-Bag_W0QQitemZ270279913443QQcmdZViewItemQQptZUS_CSA_WH_Handbags?hash=item3eedf02fe3&amp;_trksid=p3911.c0.m14&amp;_trkparms=72%3A1205%7C66%3A2%7C65%3A12%7C39%3A1%7C240%3A1318%7C301%3A1%7C293%3A1%7C294%3A50
现在这个正则表达式在 PHP 中通不过
望高人帮忙修改下,或指点下

解决方案 »

  1.   


    <?php
    $gethtml=file_get_contents ("http://shop.ebay.com/merchant/aboutsales");
    $pat ="href=(?<web_url>[\s\S]*?)>|href=""(?<web_url>[\s\S]*?)""|href='(?<web_url>[\s\S]*?)'";
    preg_match_all($pat,$gethtml,$array);
    foreach ($array[0] as $u)

    $url = $u; 
    echo trim($u)."<br>";
    }
    ?>
    在 PHP 中错误提示为 Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
      

  2.   

    $pat ="/href=(?<web_url>[\s\S]*?)>|href=""(?<web_url>[\s\S]*?)""|href='(?<web_url>[\s\S]*?)'/";
      

  3.   

    谢谢二楼的
    不行
    出错提示为: 
     syntax error, unexpected T_CONSTANT_ENCAPSED_STRING 
      

  4.   

    <?php
    $gethtml=file_get_contents ("http://shop.ebay.com/merchant/aboutsales");
    $pat ="/href=(\w+[\s\S]*)|href=\"(\w+[\s\S]*)\"|href=\'(\w+[\s\S]*?)\'/U";preg_match_all($pat,$gethtml,$array,PREG_PATTERN_ORDER);
    foreach ($array[0] as $u)

    $url = $u; 
    echo trim($u)."<br>\n";
    }
    ?>