You can use
(?:SELECT\s*)(.*?)(?:,\s*SUM.*)
to create a single capturing group.
The two (?:...)
make non-capturing groups.
The (.*?)
is a non-greedy group, which will stop before the FIRST “SUM” instead of the last one.
0
solved (Python/ Regular Expression) How to select text between two given words?