photosynthesis
photosynthesis

Reputation: 2890

How to extract the zip code from a line of address?

I've been working on this for a while, but got no solution. The problem is I have multiple lines of addresses like the following:

Enright Ave 98213         62330   Saint Louis       Missouri        314-544-0921 

I've considered to break the line by empty space to match the five consecutive number as the zip code (62330), but this does not work since sometimes the address has such label (98213) in it, can anybody provide some suggestions on it? thanks

Upvotes: 0

Views: 863

Answers (2)

lubert
lubert

Reputation: 119

Try this:

ack yourfile.txt -o --match '[0-9]{5}(?!.*([0-9]{5}))'

What this does is find the last 5 digit number on each line

Upvotes: 1

Elfentech
Elfentech

Reputation: 747

This seems to work: ([0-9]*[-]*[0-9]*)* when testing your line here

Upvotes: 0

Related Questions