Hello I would like help creating a regex that replaces all html tags but when there is an end div and start div next to each other it adds a space, so for example
This <b>is</b> <div>a</div><div>test</div>
This is a test
What I currently have for regex is /(<([^>]+)>)/ig which will replace all html tags but Im wondering how do I also add a space whenever there is a closing div and starting div next to each other.
I tried using /(<([^>]+)>)/ig to replace the html which works but I need help with the spacing on divs when they are next to each other
2
Answers
JS has built-in support for HTML parsing. Use it instead:
Try it:
This removes all html tags (https://regex101.com/r/t7WJex/1),
but you need a callback to insert a space between a closing and open div.