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

81
Visualizações
Regex get text between first p tags

I'm trying to edit the Original code to get the first p tag from product.description and tried the New Code, but with no success. Is there another method anyone can recommend? Thanks in advance for your help.

Original Code:
if (quickview.find('.des').length > 0) {          
  var description = product.description.replace(/(<([^>]+)>)/ig, "");
  quickview.find('.des').text(description);
}

New Code:
if (quickview.find('.des').length > 0) {
    var description = product.description.match(/<p>(.*?)<\/p>/g, "");
    quickview.find('.des').text(description);
}

Example parse for New Code:

<p>First inner content needed.</p> <p>content...</p> <span>content...</span>

I'm trying to grab everything inside the first paragraph only and need to remove all p tags and any other tags after.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

if (quickview.find('.des').length > 0) {                    
  var description = product.description.match(/<p class="desQuickView">(.*?)<\/p>/g, "").map(function(val){
       return val.replace(/(<([^>]+)>)/ig, "");
  });
  quickview.find('.des').text(description);

I found a way to target my first paragraph by adding a class name. Then I look for all tags and replaced them with an empty strings.

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