Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Grab zip codes out of an HTML page

by Falkkin (Chaplain)
on Feb 24, 2001 at 08:56 UTC ( #60611=snippet: print w/replies, xml ) Need Help??
Description: Takes in an HTML page and extracts everything that looks like a ZIP code (that is, 5 digits in a row.) Prints them out, separated by commas. I'm sure there's an better way to do this, but thought I'd share. :)
cat zips.html | perl -ne 's/(\d{5,})//g; print "$1," if $1'
Replies are listed 'Best First'.
Re: Grab zip codes out of an HTML page
by damian1301 (Curate) on Feb 24, 2001 at 09:31 UTC
    Wouldn't the s/(\d{5,})//g; match 5 or more instances of consecutive numbers? So if, in a webpage, there is 123456778990, it would match all of the numbers and return them in $1 A better solution to this would be to omit the comma and result with this


    But, since your not actually making a substitution in that code, you should just use a match.


    That way you don't have to falsely delete anything and its much more tidier :). Also, now you can catch the full zip code for better accuracy (eg. 12345-1234). Hope I helped.

    UPDATE:Thanks albannach for pointing out my typing mistake and for suggesting the (-\d{4})? part :)

    Almost a Perl hacker.
    Dave AKA damian

    I encourage you to email me
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://60611]
[LanX]: Network (1976 film) yeah
[LanX]: yeah, we just had a discussion at work that SciFi in the 70s had more inovation
[LanX]: (movies)
[Your Mother]: Real ideas. Ideas grounded in reality as well.
[LanX]: still some good newer ones. Oblivion had a great design, Moon was well acted
[Your Mother]: Moon was mind bending and lovely and what's his nose Sam is *always* fun.
[LanX]: the new BS Galactica series is my all time SoapFiction favourite ...
[Your Mother]: I even liked "The Arrival" and I generally hate time travel (oriented) stuff.
[Your Mother]: Gotta go. Stay out of trouble.
[LanX]: no worries ... mainland Europe is safe ;-P

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2018-03-19 15:08 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.