Impossible.
Regular expression's can't do that.
It has to do with the complexity of the grammar you're using, and regular expressions are a level below what you need.
(Edit: Specifically, the rule of thumb is 'regular expressions can't count').
Now, fear not, for this is easy to do with a simple, straight forward parser
Lo and behold, try to understand this code, and though shall be enligthend (*)
code:
<?php
$strText = "This is a test @admin_only(<a href='abcd?123=@field(Yabba);'>This is the link</a> ); of the emergency broadcast system.";
$iOffset = 0;
$arrResults = array(); //array(array(command,parameter))
while (true)
{
$iOffset = strpos($strText,'@',$iOffset);
if ($iOffset === false)
break;
$strCommand = '';
while (($strText{$iOffset} != '(') && ($iOffset < strlen($strText)))
{
$strCommand .= $strText{$iOffset};
$iOffset++;
}
$strParameter = '';
$iOpenCounter = 1;
$iCloseCounter = 0;
$iInnerOffset= 1; //so we don't count the opening ( twice
while ($iOffset + $iInnerOffset < strlen($strText))
{
if ($strText{$iOffset + $iInnerOffset} == '(')
$iOpenCounter++;
elseif ($strText{$iOffset + $iInnerOffset} == ')')
$iCloseCounter++;
else
$strParameter .= $strText{$iOffset + $iInnerOffset};
if ($iOpenCounter == $iCloseCounter)
break;
$iInnerOffset++;
}
$arrResults[] = array($strCommand,$strParameter);
$iOffset += 1; //we could advance expression length, but then we wouldn't catch any commands within a expression
}
print_r($arrResults);
?>
* no gurantee for enligthenment.
so long,
Tyberius Prime.
[This message has been edited by Tyberius Prime (edited 12-15-2003).]