Insert multiple line breaks into a JavaScript string (regex) (CodeMirror) -
i have few strings , insert line breaks them @ points.
i figured out few of logistics whole can't seem crack problem, because have limited experience regex.
basically have long string of xml tags on 1 line. want add line breaks @ points data more formatted , looking nice. using codemirror display data on webpage reason on line #1.
so need go this:
<sample><name></name><phonenumber><areacode></areacode><number></number></phonenumber></sample> to this:
<sample> <name></name> <phonenumber> <areacode></areacode> <number></number> </phonenumber> </sample> codemirror take care of rest of formatting need insert line breaks in right spot using regex or loop of sort. tags or can change guessing regex has used.
i have had success inserting line breaks \n , 
 can't seem regex detect proper locations.
any appreciated. thanks.
update overlooked brackets in fact being sent < , >
so example tag like:
<phonenumber> or
</phonenumber> so need insert \n after every > closing tag or beginning tag contains children tags.
there dragons here.
i'd point very similar question answered awhile ago job of explaining why should not try parse xml unless know you're doing.
use xml deserializer if want nice line breaks , sort of thing.
Comments
Post a Comment