/name=(")? # "name" attribute followed by optional quote ([^(?(1)"|\s\])]+) # if the quotation mark was present, match until another one, otherwise stop at whitespace or a bracket (?(1)") # match end quote, if applicable /xi