I have the following possible strings that I need to turn into arrays so I can feed them into an html generator. I am not staring with html or XML, I am trying to create a shorthand that will allow me to populate my html objects much simpler and faster with more readable code.id='moo'id = "foo" type= doo value ='http://stackoverflow.com/questions/3687511/do/"o'on_click='monkeys("bobo")'I need to pull out the attribs and their corresponding values. These attrib strings are not associated with an html or xml tag. And I would like to do it with 1 to 3 regular expressions
- The value may be encapsulated by either single or double quotes
- If the value is encapsulated by quotes it may also contain whitespace, quotes different from encapsulating quotes or escaped quotes that are same as the encapsulating quotes.
- There may or may not be whitespaces between the attrib and =, and the = and value.
- \[code\]/[\s]+/\[/code\] - Return attrib/value pairs only if there was no whitespace around the =
- \[code\]/(?<==)(\".*\"|'.*'|.*)$/\[/code\] - Returns value including the encapsulating quotes. It does ignore escaped quotes within the value though
- \[code\]/^[^=]*/\[/code\] - Returns the attribute just fine. regardless of whitespace between attrib and =