I have a Regex on SQL problem here. for SQL union query of the form:
Select a From (subquery1) union (subquery2)
I though this would be a simple Regex to match things within the From clause, I had the following Regex:
\((?<subquery1>.*)\) union \((?<subquery2>.*)\)
But later I discover things could go recursive, the 2 subquery could also contain union case again, For example:
(
(select a from b) union (select x from b)
) union (
(select a from b) union (select x from b)
)
And this completely mess up my Regex capture, subquery1 would capture the first union instead of the second one if it is non greedy, and it would capture everything until third union if it is greedy. I had also tried adding the non-greedy ? operator to both capture clause but no luck there.
I need enlightenment please, many thanks
PS: I had a custom database sit on top of MS SQL server 2012, I need to parse standard SQL select query, and made some modification to table names; numerical operation to few columns. Thus generating a modified but still standard SQL query, and pass it to SQL server