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

160
Vistas
Using regex to capture a value in a text line

I have a text line and I need capture the value "Keyword" key.

In this sample the value is "ConquestImageDate".

With my code below I can capture the value as ConquestImageDate".

But it has a '"' on the end.

I know I can use a replace to get rid off it.

But, I´d like to do it in the regex.

let line =
  '(0008,0023) VERS="CQ"   VR="DA"   VM="1"    Keyword="ConquestImageDate"             Name="Conquest Image Date"';
const re = /Keyword=\"\s*(\S+)/;
m = re.exec(line);
console.log(m[1]);
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You are not matching the closing ", and as exec might yield null you can check for m first before indexing into it.

let line =
  '(0008,0023) VERS="CQ"   VR="DA"   VM="1"    Keyword="ConquestImageDate"             Name="Conquest Image Date"';
const re = /Keyword="\s*(\S+)"/;
m = re.exec(line);
if (m) {
  console.log(m[1]);
}

If there can also be unwanted whitespace chars at the end, you could making the \S non greedy.

let line =
  '(0008,0023) VERS="CQ"   VR="DA"   VM="1"    Keyword="ConquestImageDate"             Name="Conquest Image Date"';
const re = /Keyword="\s*(\S*?)\s*"/;
m = re.exec(line);
if (m) {
  console.log(m[1]);
}


You are matching Keyword which is singular, but if in any case you want to match spaces or newlines as well between the double quotes

\bKeyword="\s*([^"]*?)"

Regex demo

about 4 years ago · Santiago Trujillo 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