Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!