PHP - 大海捞针中的针在被类似的干草堆包围时无法正常工作

Anyone know how to modify the scraper below to achieve the desired result:

Array ( [0] => Gold_Needle [1] => Silver_Needle )

The code can be ran online @ http://ideone.com/QATj5a

Result is:

Array ( [0] => this is a bunch of hay hay1= Gold_Needle [1] => Silver_Needle )

Desired Result is:

Array ( [0] => Gold_Needle [1] => Silver_Needle )

Use $starts and $ends array to build a lookahead regex like this:

(hay1=\h*\K(?:.(?!hay1))*?(?= hay=Gold))|(hay2=\h*\K(?:.(?!hay2))*?(?= hay=Silver))

Code:

$haystack='Data set 1: hay2= this is a bunch of hay  hay1= Gold_Needle hay=Gold
             Data Set 2: hay2=Silver_Needle hay=Silver';

$needle1_Begin='hay1=';
$needle2_Begin='hay2=';

$needle1_End='hay=Gold';
$needle2_End='hay=Silver';

$starts = array($needle1_Begin,$needle2_Begin);
$ends = array($needle1_End,$needle2_End);

$re = array_reduce($starts, function($res, $e) use (&$ends) {
    $res .= '(' . $e . '\h*\K(?:.(?!' . $e . '))*?(?= ' . current($ends) . '))|';
    next($ends); return $res;} );

$re = '/' . substr($re, 0, -1) . '/';

if (preg_match_all($re, $haystack, $m))
   print_r($m[0]);

output:

Array
(
    [0] => Gold_Needle
    [1] => Silver_Needle
)