Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda