title: JavaScript Replace - Convert br Tags To New Lines
body: <p>I have a JavaScript function that looks like this:</p>
  
  <pre><code>function onAfterTranslate(item, translator) {
  var thing = item.translated_text;
  document.myform.keywords.value = "Translated Text:\r\n\r\n" + thing.replace(/&lt;br&gt;/g, "\r\n");
  }
  </code></pre>
  
  <p>The parameter named item is an object, which includes an property called <code>translated_text</code>.</p>
  
  <p>These are the contents of this variable:</p>
  
  <pre><code>mono &lt;br&gt; toro &lt;br&gt; gato &lt;br&gt; perro &lt;br&gt; elefante 
  </code></pre>
  
  <p>What I want to do is convert the <code>br</code> tags to newline characters. (Ideally, it should look for optional spaces immediately before and after the br tag, and it should also accept any of the valid formats of br tag that exist, but that's not crucial at the moment.)</p>
  
  <p>However, the replace command in the above code is not working, and I can't work out why.</p>
  
  <p>If I remove the replace command so the line ends with the variable name thing, then it behaves as expected, updating the textarea box in my form with the correct value.</p>
  
  <p>Even if I try replacing the letter "o" with an asterisk, it still doesn't work, which would suggest I'm doing something fundamentally wrong here.</p>
  
  <p>Any suggestions?</p>