I have a string that contains multiple WIKI-type tags. e.g. [[TAG:4567]]
. I need to identify/extract all tags from the string so I can perform substitution later.
For example, for this string:
this is a test [[TITLE]] of more test [[LINK:27654]]
I want an array of:
0: [[TITLE]]
1: [[LINK:27654]]
I thought that PHP preg_match might work, but it returns a whole bunch of extra character between the regexp matches. But I think it only works with one match in the subject string. This is what I tried:
$subject = "this is a test [[TITLE]] of more test [[LINK:27654]]";
preg_match( '/(?<=\[\[)(.*)(?=\]\])/', $subject, $matches );
print_r($matches);
But it gives me:
Array (
[0] => TITLE]] of more test [[LINK:27654
[1] => TITLE]] of more test [[LINK:27654
)
Which isn't what I need. Is there a simple way to extract the tags? I'd really like to avoid iterating through the string and extracting manually.