D
D
Dmitry Logvinenko2015-08-05 01:34:27
SQL
Dmitry Logvinenko, 2015-08-05 01:34:27

How to adequately parse SQL using RegEx?

Goodnight.
There is a bunch of some SQL-INSERTs from which, using the scientific parsing method, it is necessary to isolate the following:

  • The names of the tables where the data is inserted (excuse the Japanese), including OPENQUERY,
  • From where the data is sucked in for inserts. Including the same OPENQUERY plus subqueries, JOIN (including comma-separated cross joins, up to tables).

All expressions are single-line, without extra spaces, tabs, comments. The parser enters one at a time.
Here: regex101.com/r/iS2fK9/1 my coprocode implementation, but the idea should be clear + request example.
Everything in the “implementation” would be fine, but it only tightens either the first FROM with its table, or the last one (JOIN) - if I use greedy quantification.
Are there ways to win this? Or maybe I did not take up the problem with those means at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Taratin, 2015-08-05
@Taraflex

Parse SQL with RegEx

No way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question