2 个回答
public static void main(String[] args) {
    System.out.println(getTargetUrl("itemUrl = 'http://detail.tmall.com/item.htm?id=529310757468'"));
}

private static String getTargetUrl(String fullUrl) {
    String reg = "itemUrl = '(.*)'";
    Pattern pattern = Pattern.compile(reg);
    Matcher matcher = pattern.matcher(fullUrl);
    if (matcher.find()) {
        return matcher.group(1);
    }

    return null;
}

PatternMatcher的具体用法可以参考我的一篇文章https://segmentfault.com/a/1190000002923343

preg_match_all('#itemUrl = \'(.*?)\'#i',$html,$matchs);
foreach($matchs as $k=>$v){
    echo $v[1]."\r\n";
}
推荐问题
宣传栏