I am attempting to use preg_match to find and replace based on some parts that are found in the string, I am able to do this by sepparating the script into different patterns but I wonder if this can be done with ony one pattern.

For instance I strings like this

{container id=1 class=basic}
{container class=advanced id=5}

and I should be translating that into
<div class="basic"><a href="/index.php?id=1"></a></div>
<div class="advanced"><a href="/index.php?id=5"></a></div>

At the moment I am able to do them but they always have to respect the order of
{container class=someclassname id=someid}

if by any chance the user enters
{container id=someid class=someclassname}

Then the script does not work

I found that enclosing the pattern in parenthesis then I can do something like
$replcement='<div class="${1}"><a href="/index.php?id=${2}"></a></div>';

but if my pattern looks something like this
({test) (id=\d*|class=\w*) (id=\d*|class=\w*)(})

How could I know if they first entered the id or the class name