Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I’d start from the back since, as far as I know, a city name cannot contain numbers (but it <em>can</em> contain spaces (first example I’ve found: “<a href="http://en.wikipedia.org/wiki/Weil_der_Stadt" rel="nofollow">Weil der Stadt</a>”). Then the five-digit number before that must be the zip code.</p> <p>The number (possibly followed by a single letter) before that is the street number. Note that this can also be a <em>range</em>. Anything before that is the street name.</p> <p>Anyway, here we go:</p> <pre><code>^((?:\p{L}| |\d|\.|-)+?) (\d+(?: ?- ?\d+)? *[a-zA-Z]?) (\d{5}) ((?:\p{L}| |-)+)(?: *\(([^\)]+)\))?$ </code></pre> <p>This correctly parses even arcane addresses such as “Straße des 17. Juni 23-25 a 12345 Berlin-Mitte”.</p> <p>Note that this doesn’t work with address extensions (such as “Gartenhaus” or “c/o …”). I have no clue how to handle those. I rather doubt that there’s a viable regular expression to express all this.</p> <p>As you can see, this is a quite complex regular expression with lots of capture groups. <em>If</em> I would use such an expression in code, I would use named captures (Java 7 supports them) and break the expression up into smaller morsels using the <code>x</code> flag. Unfortunately, Java doesn’t support this. This s*cks because it effectively renders complex regular expressions unusable.</p> <p>Still, here’s a somewhat more legible regular expression:</p> <pre><code>^ (?&lt;street&gt;(?:\p{L}|\ |\d|\.|-)+?)\ (?&lt;number&gt;\d+(?:\ ?-\ ?\d+)?\ *[a-zA-Z]?)\ (?&lt;zip&gt;\d{5})\ (?&lt;city&gt;(?:\p{L}|\ |-)+) (?:\ *\((?&lt;suffix&gt;[^\)]+)\))? $ </code></pre> <p>In Java 7, the closest we can achieve is this (untested; may contain typos):</p> <pre><code>String pattern = "^" + "(?&lt;street&gt;(?:\\p{L}| |\\d|\\.|-)+?) " + "(?&lt;number&gt;\\d+(?: ?- ?\\d+)? *[a-zA-Z]?) " + "(?&lt;zip&gt;\\d{5}) " + "(?&lt;city&gt;(?:\\p{L}| |-)+)" + "(?: *\\((?&lt;suffix&gt;[^\\)]+)\\))?" + "$"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload