Concatenating variable into a regex php -
i have these arrays (array , array2)
$urls = array("http://piggington.com/pb_cash_flow_positive")
i have regular expression
(preg_match("/\/{2}.*?\./", $array[$i], $matches))
it checks comes after 2nd slash , before 1st dot. find
/piggington.
now want concatenate variable inside following regular expression, search specific string.
i tried:
$matches_imploded = implode($matches); $matches_imploded = preg_quote($matches_imploded, '/'); $match_with_other_array = preg_grep("/\/{2}".$matches_imploded."\./", $array2);
but it's not finding matches.. doing wrong? should looking inside array2 , making positive match $matches_imploded
between second slash , first dot found $matches_imploded
to match comes after //
, before first dot, need use \k
or positive lookbehind.
preg_match("~/{2}\k[^.]*(?=.)~", $array[$i], $matches) $matches_imploded = implode($matches); $matches_imploded = preg_quote($matches_imploded, '/'); $match_with_other_array = preg_grep("/\/{2}".$matches_imploded."\./", $array2);
Comments
Post a Comment