stone stone - 1 year ago 74
PHP Question

preg_match and a troublesome regex

Could some one tell me why

$content = 'random ${one.var} ${two.var} random';

preg_match('/(?:(?<=\$\{))([\w.]+){1}(?=\})/i', $content, $matches);

is returning



What i want is


Answer Source

Both the whole regex (0) as the inner capture () (1) match the same thing, so that part of the match makes sense. You probably want preg_match_all, which captures all matches...

preg_match_all('/(?<=\$\{)[\w.]+(?=\})/i', $content, $matches);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download