Reputation: 6638
I need to extract the zipcode from file's line. each line contains an adress and is formatted in a different way. eg. "Großen Haag 5c, DE-47559 Kranenburg" or "Lange Ruthe 7b, 55294 Bodenheim"
the zipcode is always a five digit number and sometimes follows "DE-". I use Java. Thanks a lot!
Upvotes: 1
Views: 755
Reputation: 336168
\b\d{5}\b
will match 5 digits if they are "on their own", i.e. surrounded by word boundaries (to ensure we're not matching substrings of a longer sequence of numbers, although those will probably be rare in an address file).
Remember that you'll need to escape the backslashes in a Java string ("\\b\\d{5}\\b"
).
Upvotes: 3