Python 匹配街道名称和门牌号的正则表达式

Python regex to match street name and house number

我有一个匹配 街道名称 的正则表达式(参见 demo 1) and I have a regex which matches possible house numbers in Germany (see demo 2)。每个正则表达式都工作得很好。在下一步中,我想结合两个正则表达式(街道名称 + 门牌号)。换句话说,我正在寻找一个匹配 both 街道名称和门牌号的正则表达式。

我准备了一个demo 3 with examples. I know these examples are not complete if you compare it with the strict rules here,但对于我的用例来说已经足够了。

由于正则表达式是一种基于规则的语言,让我试着用文字来解释规则:

我的问题: 我对每个单独的案例都有解决方案(参见演示 1 和 2),但我的问题是我不知道如何将两个正则表达式合并为一个(参见演示 3)。

street names 的工作正则表达式:

^(?:[A-Z] \d|[^\W\d_]{2,}\.?)(?:[- '’][^\W\d_]+\.?)*$

house numbers 的工作正则表达式:

^[1-9]\d{0,3} ?[a-zA-Z]?(?: ?[/-] ?[1-9]\d{0,3} ?[a-zA-Z]?)?$

根据上面显示的正则表达式,我如何将它们结合起来以匹配我在 demo 3 中显示的示例?

将 2 个正则表达式合并为一个:

^(?:[A-Z] \d|[^\W\d_]{2,}\.?)(?:[- '’][^\W\d_]+\.?)*\s+[1-9]\d{0,3} ?[a-zA-Z]?(?: ?[/-] ?[1-9]\d{0,3} ?[a-zA-Z]?)?$

Updated RegEx Demo