[update:] Accepted answer suggests, this can not be done with the python re library in one step. If you know otherwise, please comment. I’m reverse-engineering a massive ETL pipeline, I’d like to extract the full data lineage from stored procedures and views. I’m struggling with the following regexp. TLDR: I’d like to capture from a string like where a,b,e,f,h match