I need to remove some info contained in a text-area tag and have tried different things without positive results. The text I need to remove is contained between the "Address:" and the inmediatly following "br>".
I know it would be easier if they were some IDs, tags or classes to help indentify the correct place, but unfortunately I cant modify the content of the textarea
<textarea id="source">
[uncertain html code, maybe including other <br> tags]
Name: ABCDESFGHIJKLMN<br>
Address: THIS IS THE INFO I WOULD LIKE TO REMOVE <br>
Phone: 0123-456-7890<br>
[uncertain html code, maybe including other <br> tags]
</textarea>
What I have tried is the following code in different combinations:
var result = document.getElementById('source').value;
result = result.replace(/Address:.*br>/g, "");
You had it almost correct. First of all you need put the modified value back into the textarea, but also, your replaced string will replace whole address line. This should do it:
var result = document.getElementById('source').value;
result = result.replace(/(?<=Address:).*(?=<br>)/g, "");
document.getElementById('source').value = result;
<textarea id="source">
[uncertain html code, maybe including other <br> tags]
Name: ABCDESFGHIJKLMN<br>
Address: THIS IS THE INFO I WOULD LIKE TO REMOVE <br>
Phone: 0123-456-7890<br>
[uncertain html code, maybe including other <br> tags]
</textarea>
You're missing adding the value back to the textarea. Your result variable is currently holding the modified string, but you need to adjust the value of the textarea element.
An example would be using this line at the bottom of the code you referenced:
document.getElementById('source').value = result;
check this
var result = document.getElementById('source').value;
var replaced = result.replace(/(?<=Address:).*(?=>)/g, "");
document.getElementById('source').value = replaced;
<textarea id="source">
[uncertain html code, maybe including other <br> tags]
Name: ABCDESFGHIJKLMN<br>
Address: THIS IS THE INFO I WOULD LIKE TO REMOVE <br>
Phone: 0123-456-7890<br>
[uncertain html code, maybe including other <br> tags]
</textarea>