php - RegEx for preg_match_all not working -


this string ($string):

    swatch: 'http://abc.com/aa.jpg',     zoom:[       'http://abc.com/bb.jpg'     ],     large:[        'http://abc.com/cc.jpg'     ], 

i use following pattern in php file , want match http://abc.com/bb.jpg:

preg_match_all('/(?<=zoom:\[\s{15}\').*(?=\')/', $string, $image); 

but nothing returned. should do?

to make simpler, won't use around , although said need s modifier, wrong it's used match new lines dots . won't using here, \s matches new line:

$string = <<<jso         swatch: 'http://abc.com/aa.jpg',         zoom:[           'http://abc.com/bb.jpg'         ],         large:[            'http://abc.com/cc.jpg'         ], jso; preg_match_all('/zoom:\[\s*\'(?<img>[^\']*)\'\s*\]/', $string, $m); print_r($m['img']); 

output:

array (     [0] => http://abc.com/bb.jpg ) 

explanation:

/ # starting delimiter     zoom:\[ # matches zoom:[     \s* # matches spaces, newlines, tabs 0 or more times     \'  # matches '     (?<img>[^\']*) # named group, matches until ' found     \'  # matches '     \s* # matches spaces, newlines, tabs 0 or more times     \]  # matches ] / # ending delimiter 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -