以下是需要preg_matched的文本。
/* * product 2: * catalogServiceType = 2 * catalogCacheType = 1 * catalog2RemoteCacheActive = false */ var objProduct881705 = new ProductStyle("2","881705","","4149367","247",false,false,false,false,'','',"35401",false,'$79.50',true,false,false,false,0,false,true,false,true,99,5,"First content that needs to be matched",'Color',"","Machine.","","false","false","false",0,0,"C1","1","",true);obj={'S':'http://domainname.com/mini/image.jpg', 'L':'http://domainname.com/main/image.jpg'};
我希望能够从上面的文字中获取以下内容:
1. First content that needs to be matched
2. http://domainname.com/main/image.jpg
你怎么建议我能做到这一点?
答案 0 :(得分:0)
正则表达式新手在这里得到了一些东西:
/\((.+?,){25}\"(.+?)\".+?'L':'(.+?)'/
答案 1 :(得分:0)
以下是我解决它的方法:
preg_match('/new ProductStyle\(([^\)]+)\)/', $html, $matches);
$jsonValues = '[' . $matches[1] . ']';
$jsonValues = preg_replace_callback("/(?<=,)'(.*?)'(?=,)/", create_function(
'$matches',
'return \'"\' . addslashes(strip_tags($matches[1])) . \'"\';'
), $jsonValues);
$values = json_decode($jsonValues);