I'd like to replace all self-closed elements to the long syntax (because my web-browser is tripping on them).
Example
<iframe src="http://example.com/thing"/>
becomes
<iframe src="http://example.com/thing"></iframe>
I'm using python's flavor of regex.
None of those solutions will accommodate attributes like foo="/>". Try:
s:<([\w\-_]+)((?:[^'">]|'[^']*'|"[^"]*")*)/\s*>:<$1$2></$1>:
Exploded to show detail:
<
([\w\-_]+) # tag name
(
[^'">]*| # "normal" characters, or
'[^']*'| # single-quoted string, or
"[^"]*" # double-quotes string
)*
/\s* # self-closing
>
This should always work provided that the markup is valid. (You could rearrange this using lazy quantifiers if you so chose; e.g. '[^']' => '.*?'.)
Use this python regex:
(<(\w+)[^<]*?)/>
It differs from @Kinopiko's in that it will handle nested elements.
Explanation of Regex
Then just replace with this statement:
\1></\2>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With