Question

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!

Was it helpful?

Solution

\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").

OTHER TIPS

Pattern.matcher("[0-9]{5}")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top