None of these solutions will contain attributes such as foo = "/">. Try:
s:<([\w\-_]+)((?:[^'">]|'[^']*'|"[^"]*")*)/\s*>:<$1$2></$1>:
Blown up to show details:
<
([\w\-_]+)
(
[^'">]*| # "normal" characters, or
'[^']*'| # single-quoted string, or
"[^"]*"
)*
/\s*
>
This should always work as long as the markup is valid. (You can change this using lazy quantifiers, if you chose so, for example, "[^ ']' => '. *?'.)
source
share