Extract companies' register number in Python by getting the next word
问题 I am trying to get the German Handelsregisternummer (companies' register number) which usually is directly written behind the word HRB . However there are exceptions which I would like to catch with my regex. The goal is to call the function and set the keyword (in this case it is HRB ). Then the function returns the number. Please see regex demo! This is what I have so far! This doesn't catch all cases. def get_company_register_number(string, keyword): reg_1 = fr'\b{keyword}\b[,:|\s]*(\w+)'