我要在html中匹配
itemUrl = 'http://detail.tmall.com/item.htm?id=529310757468'这个,然后要拿到里面的这个
http://detail.tmall.com/item.htm?id=529310757468。(http://detail.tmall.com/item.htm?id=529310757468)这部分是会变的
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;
}
Pattern
和Matcher
的具体用法可以参考我的一篇文章https://.com/a/1190000002923343
preg_match_all('#itemUrl = \'(.*?)\'#i',$html,$matchs);
foreach($matchs as $k=>$v){
echo $v[1]."\r\n";
}