meta http-equiv content-type content text/htmlcharset=utf- li class right style margin-right px one approach is to use two regexesone to capture tags with their attributes and another to extract the name and value of each attribute attribute values might be quoted using single or double quotes (in which case they may contain whitespace and the quotes that are not used to enclose them)or they may be unquoted (in which case they cannot contain whitespace or quotesit is probably easiest to start by creating regex to handle quoted and unquoted values separatelyand then merging the two regexes into single regex to cover both cases it is best to use named groups to make the regex more readable this is not easyespecially since backreferences cannot be used inside character classes solution is provided in extract_tags pywhich is less than lines long the tag and attributes regex is just one line the attribute name-value regex is half dozen lines and uses alternationconditional matching (twicewith one nested inside the other)and both greedy and nongreedy quantifiers