Of course there are no problems. Let me break it:
\w+\s*=\s*
matches an alphanumeric keyword followed by an equal sign (which may be surrounded by a space).
"[^"]*"
matches a double double quote, followed by any number of characters except another double quote, then a (closing) double quote.
'[^']*'
does the same for single quotes.
Combining this using capture groups ( (...) ) with simple interleaving ( | ), you get
(\w+)\s*=\s*("[^"]*"|'[^']*')
In PHP:
preg_match_all('/(\w+)\s*=\s*("[^"]*"|\'[^\']*\')/', $subject, $result, PREG_SET_ORDER);
populates $result array of matches. $result[n] will contain details of matching n th, where
$result[n][0] - full match$result[n][1] contains the keyword$result[n][2] contains the value (including quotation marks)
Edit:
To map a value element without its quotes, regardless of the type of quotes used, you need a slightly more complex regular expression that uses the positive lookahead statement :
(\w+)\s*=\s*(["'])((?:(?!\2).)*)\2
In PHP:
preg_match_all('/(\w+)\s*=\s*(["\'])((?:(?!\2).)*)\2/', $subject, $result, PREG_SET_ORDER);
with the results
$result[n][0] : full match$result[n][1] : keyword$result[n][2] : quote character$result[n][3] : value
Explanation:
(["'])
source share