Just a fast replacement for any complicated regular expressions. htmltidy is much more faster than RegExp (10-50x) and alows you to get tags array (with attributes and values) from a well-formed HTML code (also works with non-well-formed, but in unpredictable way).