Another way to say this is "find all substrings within a string"; while there's a bunch of these posts on stackoverflow already, none I've found quite get the job done.
#query variable
query = "select * from table1 a join table2 b on a.id = b.id left join table3 c on b.id = c.id where x = 5;"
query_list = query.split()
#find the adjacent word in a list
def find_adjacents(some_value, some_list):
i = some_list.index(some_value)
return some_list[i:i+2]
print('from tables:', find_adjacents("from", query_list)[1])
print('join tables:', find_adjacents("join", query_list)[1])
>>>from tables: table1
>>>join tables: table2
There should be one more join tables: table3. How do I get this to print All instances of the adjacent substring "join"?