Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Remove text inside two strings

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, ""); 
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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>

about 4 years ago · Juan Pablo Isaza Report

0

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;
about 4 years ago · Juan Pablo Isaza Report

0

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>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!