Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 635765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:26:28+00:00 2026-05-13T20:26:28+00:00

I have to create a loop, and with a regexp populate any of the

  • 0

I have to create a loop, and with a regexp
populate any of the 4 variables

$address, $street, $town, $lot

The loop will be fed a string that may have info in it
like the lines below

  • '123 any street, mytown' or
  • 'Lot 4 another road, thattown' or
  • 'Lot 2 96 other road, her town' or
  • 'this ave, this town' or
  • 'yourtown'

since anything after a comma is the $town I thought

(.*), (.*)

then the first capture could be checked with (Lot \d*) (.*), (.*)
if the 1st capture starts with a number, then its the address (if word with white space its $street)
if one word, its just the $town

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:26:28+00:00Added an answer on May 13, 2026 at 8:26 pm

    Take a look at Geo::StreetAddress::US if these are U.S. addresses.

    Even if they are not, the source of this module should give you an idea of what is involved in parsing free form street addresses.

    Here is a script that handles the addresses you posted (updated, earlier version combined lot and number into one string):

    #!/usr/bin/perl
    
    use strict; use warnings;
    
    local $/ = "";
    
    my @addresses;
    
    while ( my $address = <DATA> ) {
        chomp $address;
        $address =~ s/\s+/ /g;
        my (%address, $rest);
        ($address{town}, $rest) = map { scalar reverse }
                            split( / ?, ?/, reverse($address), 2 );
    
        {
            no warnings 'uninitialized';
            @address{qw(lot number street)} =
                $rest =~ /^(?:(Lot [0-9]) )?(?:([0-9]+) )?(.+)\z/;
        }
        push @addresses, \%address;
    }
    
    use Data::Dumper;
    print Dumper \@addresses;
    
    __DATA__
    123 any street,
    mytown
    
    Lot 4 another road,
    thattown
    
    Lot 2 96 other road,
    her town
    
    yourtown
    
    street,
    town
    

    Output:

    $VAR1 = [
              {
                'lot' => undef,
                'number' => '123',
                'street' => 'any street',
                'town' => 'mytown'
              },
              {
                'lot' => 'Lot 4',
                'number' => undef,
                'street' => 'another road',
                'town' => 'thattown'
              },
              {
                'lot' => 'Lot 2',
                'number' => '96',
                'street' => 'other road',
                'town' => 'her town'
              },
              {
                'lot' => undef,
                'number' => undef,
                'street' => undef,
                'town' => 'yourtown'
              },
              {
                'lot' => undef,
                'number' => undef,
                'street' => 'street',
                'town' => 'town'
              }
            ];
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to create a loop that will go though movie clip names allowing
I have a loop which needs to create an unspecified and indefinite amount of
I have a short loop I used to create several .csv files. The loop
I have a for loop that creates multiple UIImageViews that I add to self.view
I have a recordset loop that creates a table, and every 9 items it
I have loop to create a column of button and now i wish to
I have to create a DSL for non-programmers (customers of our company) that needs
How I love regex! I have a string which will be a mangled form
In my CSS I have to create classes that make reference to a 'hair
I have a wordpress theme in which i have to create a page that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.