How to trasform correctly a string like this:
html attr = "value" attr2 = 'UnmatchInSubstrings' some \escapedTag content subtag subcontent /subtag br / /html
in:
<html attr = "value" attr2 = 'UnmatchInSubstrings'> some escapedTag content <subtag>subcontent</subtag> <br /> </html>
Requirements:
- Does not match tags in substrings (text in "" and '')
- Use the character \ to escape a tag you want as normal text. The escaped tag losts its slash.
- Match unclosed tags like br /
I have tried with a regex like the follow, that does not works as excepted:
/([^\\]\S+[\s[\"|\']+\s\S[\"|\']+]*)+/g
.
For my attempts, I'm using regex101.com
Thank you in advance and sorry if it is not well comprehensible :)
<>)someisn't an attribute? Orbrisn't part of content but a tag? You'll need AI, I think.