Q:

Javascript Regex or Jquery to parse html strings?

I have some texts returned by Google Maps, I would like to remove the div tags, (replacing them by <br /> would be the perfect deal
'Turn <b>right</b> onto <b>Route de Sospel/D2566</b>
     <div style="font-size:0.9em">Continue to follow D2566</div>
    <div style="font-size:0.9em">Go through 6 roundabouts</div>'

=>
'Turn <b>right</b> onto <b>Route de Sospel/D2566</b><br />
Continue to follow D2566<br />Go through 6 roundabouts'

I don't know which solution would be better either find the appropriate regex, might be hard, but more performant than evaluating this string with $() Jquery and them find('div').text() inside ...
thanks for your advices (or sample code)

A:

Assume your content was like this:
<div id="content">
Turn <b>right</b> onto <b>Route de Sospel/D2566</b>
     <div style="font-size:0.9em">Continue to follow D2566</div>
    <div style="font-size:0.9em">Go through 6 roundabouts</div>
<div>​

This should work, just replace the #content selector according to how you get your data:
​$("#content​​​​​​​​​ div").each(//get all div's inside #content
    function(i,el) {//i is an index el refers to each element.
        $(el).replaceWith("<br/>" + $(el).text());
    }//replace the element with the text of each element
);​​​​​​​​
//alert($("#content").html());

​See working demo:
http://jsfiddle.net/rYeUH/

