How to extract a substring beginning with a specific substring and ends with another specific substring?

import re

sentence = "1111Austria9999Salzburg (SZG)Vienna (VIE)1111Bosnia-Herzegovina9999Sarajevo (SJJ)1111Bulgaria9999Bourgas (BOJ)Varna (VAR)"

regs = re.findall(r'[A-z]+\s\([A-Z]{3}\)', sentence)
print(regs)

This follows from my logic in the comments.

Leave a Comment