Match all whitespace in an HTML string with JavaScript

keevekayaks

New Member
Lets say you have an HTML string like this:\[code\]<div id="loco" class="hey" >lorem ipsum pendus <em>hey</em>moder <hr /></div>\[/code\]And need to place \[code\]<br/>\[/code\] elements after every space character.... which I was doing with:\[code\]HTMLtext.replace(/\s{1,}/g, ' <br/>');\[/code\]However, the problem is that this inserts breaks after space characters in-between tags (between tag properties) too and I'd of course like to do this for tag textual contents only. Somehow I was always really bad with regular expressions - could anyone help out?So basically do my original whitespace match but only if its not between < and > ?
 
Back
Top