pythonregex

How to add one more pattern to my street-name regex?


I already have a working example of a regex that matches most German street names. However, I recently learned, that the following patterns are possible as well:

How can I build this pattern into my existing Python-regex?:

^(?:[^\W\d_]+\.?|\([^\W\d_]+\.?\))(?:[- '’](?:[^\W\d_]+\.?|\([^\W\d_]+\.?\)))*$

Solution

  • You can just add it with an |. It also seems that your pattern can be heavily simplified:

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

    https://regex101.com/r/WRd1jx/7