正则表达式以获取双花括号“{{}}”内的值

Regular expression in PHP to fetch the text quoted inside with "{{ }}" in an array.

For eg:

$str = "This is sample content with a dynamic value {{value1}} and also have more dynamic values {{value2}}, {{value3}}";

Need output as like below array,

array(value1,value2,value3);

This will work:

$str = "This is sample content with a dynamic value {{value1}} and also have more dynamic values {{value2}}, {{ value3 }}";
if (preg_match_all("~\{\{\s*(.*?)\s*\}\}~", $str, $arr))
   var_dump($arr[1]);

OUTPUT:

array(3) {
  [0]=>
  string(6) "value1"
  [1]=>
  string(6) "value2"
  [2]=>
  string(6) "value3"
}

Use this:

preg_match_all('~\{\{(.*?)\}\}~', $string, $matches);
var_dump($matches[1]);

Output:

array(3) {
  [0] =>
  string(6) "value1"
  [1] =>
  string(6) "value2"
  [2] =>
  string(6) "value3"
}
preg_match_all('/\{\{([^}]+)\}\}/', $str, $matches);
$array = $matches[1];