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

122
Vistas
javascript - find line that starts with string and print select characters

I'm trying to parse a multline string with javascript and in the example below return "Dan Smith". My filter is close but not quite there.

var header = "Resent-From:<joesmith@domain.com>\nFrom:Dan Smith <dansmith@domain.com>\nTo:Bill Smith <dansmith@domain.com>\n"
console.log(header)

var filter = header.split("From:").pop();
console.log(filter)

edit: The goal was to retrieve "Dan Smith"

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To do it your way, you would need another split

var header = "Resent-From:<joesmith@domain.com>\nFrom:Dan Smith <dansmith@domain.com>\nTo:Bill Smith <dansmith@domain.com>\n"


var filter = header.split("From:").pop().split("<").shift().trim();
console.log(filter)

Basic regular expression can match the name.

var header = "Resent-From:<joesmith@domain.com>\nFrom:Dan Smith <dansmith@domain.com>\nTo:Bill Smith <dansmith@domain.com>\n"
console.log(header.match(/\nFrom:([^<]+)</)[1].trim());

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