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

263
Vistas
Regex: Replace content inside parenthesis of subquery in node.js

I wish to replace the a subquery to the table name inside the subquery using regex in node.js.

e.g. converting the following query:

SELECT col1
FROM (SELECT col1::DECIMAL(10),
col2,
FROM @table_name)
WHERE (COND1) AND (COND2)

To:

SELECT col1
FROM @table_name
WHERE (COND1) AND (COND2)

I have tried using:

string.replace(/\([^()]*\)/g, '') But it eliminates the entire content.

Any idea is appreciated. Thanks!

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

0

You could try the following regex replacement:

var sql = `SELECT col1
FROM (SELECT col1,
col2,
FROM @table_name)
WHERE (COND1) AND (COND2)`;

sql = sql.replace(/\([^)]*\bFROM (@[^)]+)[^)]*\)/, "$1");
console.log(sql);

But to cover all possible edge cases, you might want to use a SQL parser.

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