Separate the house number from the street name: Difference between revisions

Line 527:
│Karl-Weysser-Str. │6 │
└───────────────────┴───────────────────────┘</lang>
 
=={{header|jq}}==
{{works with|jq}}
 
Using the regex from the Perl version....
<lang jq>def regex:
"^ (?<s>.*?) \\s+"
+ " (?<n>\\d* ( \\-|\\/)? \\d*"
+ " | \\d{1,3} [a-zI./ ]* \\d{0,3}"
+ " )$";
 
# Output: {s, n}
# If the input cannot be parsed,
# then .s is a copy of the the input, and .n is "(Error)"
def parseStreetNumber:
capture(regex; "x")
// {s: ., n: "(Error)"} ;
 
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;</lang>
'''The Task'''
<lang jq>def addresses:
"Plataanstraat 5",
"Straat 12",
"Straat 12 II",
"Dr. J. Straat 12",
"Dr. J. Straat 12 a",
"Dr. J. Straat 12-14",
"Laan 1940 - 1945 37",
"Plein 1940 2",
"1213-laan 11",
"16 april 1944 Pad 1",
"1e Kruisweg 36",
"Laan 1940-'45 66",
"Laan '40-'45",
"Langeloërduinen 3 46",
"Marienwaerdt 2e Dreef 2",
"Provincialeweg N205 1",
"Rivium 2e Straat 59.",
"Nieuwe gracht 20rd",
"Nieuwe gracht 20rd 2",
"Nieuwe gracht 20zw /2",
"Nieuwe gracht 20zw/3",
"Nieuwe gracht 20 zw/4",
"Bahnhofstr. 4",
"Wertstr. 10",
"Lindenhof 1",
"Nordesch 20",
"Weilstr. 6",
"Harthauer Weg 2",
"Mainaustr. 49",
"August-Horch-Str. 3",
"Marktplatz 31",
"Schmidener Weg 3",
"Karl-Weysser-Str. 6"
;
 
def task:
"Street House Number",
"--------------------- ------------",
(addresses
| parseStreetNumber
| .n |= if . == "" then "(none)" else . end
| "\(.s|lpad(22)) \(.n)" )
;
 
task</lang>
{{out}}
<pre>
Street House Number
--------------------- ------------
Plataanstraat 5
Straat 12
Straat 12 II
Dr. J. Straat 12
Dr. J. Straat 12 a
Dr. J. Straat 12-14
Laan 1940 - 1945 37
Plein 1940 2
1213-laan 11
16 april 1944 Pad 1
1e Kruisweg 36
Laan 1940-'45 66
Laan '40-'45 (Error)
Langeloërduinen 3 46
Marienwaerdt 2e Dreef 2
Provincialeweg N205 1
Rivium 2e Straat 59.
Nieuwe gracht 20rd
Nieuwe gracht 20rd 2
Nieuwe gracht 20zw /2
Nieuwe gracht 20zw/3
Nieuwe gracht 20 zw/4
Bahnhofstr. 4
Wertstr. 10
Lindenhof 1
Nordesch 20
Weilstr. 6
Harthauer Weg 2
Mainaustr. 49
August-Horch-Str. 3
Marktplatz 31
Schmidener Weg 3
Karl-Weysser-Str. 6
</pre>
 
 
=={{header|Julia}}==
2,442

edits