I'm trying to complete a PHP app in the next 2 weeks and I just can't figure out the regular expression to parse some attribute strings.

I get random strings that are in the format of like this string: 

```
KeyName1="KeyValue1" KeyName2='KeyValue2'

```

There may be any number of key value pairs in a single string and the values can be delimited by either single quotes **'** or double quotes **"** in any combination within one string (but they are always delimited).

The key values can be of any lengths and contain any character except double quotes can't be inside double quotes and a single quotes can't be inside single quotes, but double quotes can be inside single quotes and single quotes can be inside double quotes.

The key value pairs can have any number of spaces between them and any number of spaces between the key name and the equal sign and the equal sign and the quote character that starts the key value.

I need to turn the string into an array that looks like:

```
$arrayName["KeyName1"] = "KeyValue1"
$arrayName["KeyName2"] = "KeyValue2"

```

etc.

I'm pretty sure it can be done with regular expressions but all my attempts have failed and I need some help (actually lots of help :-) to get this done and am hoping some of the amazing people here can provide that help or at least get me started.