I've edited this to be more clear and provide a solution.
I'd like to use regex to search within substrings for text starting with the characters --
and extract all text that comes after for that line. I already have both pieces successfully working separately (1. the substring search and 2. the --
search), I'm just not sure how to combine these effectively. I have a string -
qry = '''
with
qry_1 as ( -- some text
SELECT ID,
NAME
FROM ( ... other code...
),
qry_2 as (
SELECT coalesce (table1.ID, table2.ID) as ID,
NAME
FROM (...other code...
),
qry_3 as (
-- some text
SELECT id.WEATHER AS WEATHER_MORN,
ROW_NUMBER() OVER(PARTITION BY id.SUN
ORDER BY id.TIME) AS SUN_TIME,
id.RAIN,
id.MIST
FROM (...other code..
-- some other text
)
'''
re.findall
here -sub = re.findall('\),\s{2,}(.*?)as\s\(',qry)
re.findall(r'--+(.*)(.\s)',qry)
But how to incorporate step 3 successfully?
Thank you for guidance here
Step 3 successfully run
commentary = [re.findall(r'--+(.*)(.\s)', i)
for i in re.findall('\),\s{2,}(.*?)as\s\(',qry,flags=re.S)]