Reputation:
I would like to match all the patterns like [[WHATEVER]]
The text inside those two brackets can be uppercase or lowercase, it can start with space or end with space and can be made of two or more words separated by space
$string = "The [[QUICK]] brown [[FOX]] jumped over [[whatever]]";
parse $string; //I would like an result to be like array
array( 0 => "[[QUICK]]", 1 => "[[FOX]]", 2 => "[[whatever]]")
Upvotes: 3
Views: 204
Reputation: 67968
\[\[[^\]]*\]\]
This should do it.
$re = "/\\[\\[[^\\]]*\\]\\]/im";
$str = "The [[QUICK]] brown [[FOX]] jumped over [[whatever]]";
preg_match_all($re, $str, $matches);
Upvotes: 0
Reputation: 626893
You can match them like this:
$re = "/\\[{2}.*?\\]{2}/";
$str = "The [[QUICK]] brown [[FOX]] jumped over [[whatever]]";
preg_match_all($re, $str, $matches);
print_r($matches[0]);
Output of a sample program:
Array
(
[0] => [[QUICK]]
[1] => [[FOX]]
[2] => [[whatever]]
)
Upvotes: 2