My string is
string = "Amtsgericht Berlin HRB 25665"
How can I find the word before AND after the keyword HRB
?
This way I get the word after my keyword:
match = re.compile(r'HRB\s+((?:\w+(?:\s+|$)){1})')
print(match.findall(string))
>>>>> ['25665']
How can I add the keyword (HRB
) as a variable into my regex expression?