Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda